By airstanair
on Mon, 12/03/2012 - 21:10
I completed an example for ImageTarget on unity 3D? but I found a javascript method that can change 3D object with buttons.
I try it ,and it's work. But there is a problem.
When I use phone camera to focus the trackimage and use the change button, it's working, I can change 3D object on my phone screen.
But~ when I don't focus the trackimage, the 3D object is still in my phone screen. How to slove it? help me~thank you.
-------js code(I put it in AR camera)----
var
ObjectA: GameObject;
var
ObjectB: GameObject;
var
ObjectC: GameObject;
var
ObjectD: GameObject;
var
TempActor: String =
""
;
private
var
Clone: GameObject;
function
Start() {
SwitchActor(
"A"
);
}
function
Update() {}
function
OnGUI() {
GUI.BeginGroup(Rect(20, 20, 200, 315));
GUI.Box(Rect(0, 0, 200, 315),
"Actor List"
);
if
(GUI.Button(Rect(20, 30, 160, 50),
"Actor A"
)) SwitchActor(
"A"
);
if
(GUI.Button(Rect(20, 100, 160, 50),
"Actor B"
)) SwitchActor(
"B"
);
if
(GUI.Button(Rect(20, 170, 160, 50),
"Actor C"
)) SwitchActor(
"C"
);
if
(GUI.Button(Rect(20, 240, 160, 50),
"Actor D"
)) SwitchActor(
"D"
);
GUI.EndGroup();
}
function
SwitchActor(mag) {
if
(mag != TempActor) {
Destroy(GameObject.Find(
"Actor"
+ TempActor));
switch
(mag) {
case
"A"
:
TempActor =
"A"
;
Clone = Instantiate(ObjectA, Vector3(0, 0, 0), Quaternion.identity);
Clone.name =
"ActorA"
;
print(
"A"
);
break
;
case
"B"
:
TempActor =
"B"
;
Clone = Instantiate(ObjectB, Vector3(0, 0, 0), Quaternion.identity);
Clone.name =
"ActorB"
;
print(
"B"
);
break
;
case
"C"
:
TempActor =
"C"
;
Clone = Instantiate(ObjectC, Vector3(0, 0, 0), Quaternion.identity);
Clone.name =
"ActorC"
;
print(
"C"
);
break
;
case
"D"
:
TempActor =
"D"
;
Clone = Instantiate(ObjectD, Vector3(0, 0, 0), Quaternion.identity);
Clone.name =
"ActorD"
;
print(
"D"
);
break
;
}
}
}
a change 3D object button into ImageTarget example on unity3D
Hi, could you post this in the Unity section of this Forum ?
Thanks