- Home /
Question by
KimLarsson · Apr 09, 2013 at 08:11 PM ·
How do i write a script that switches between 2 variables.
How do i write a script that when triggered switches out "camera1" for "camera2" in the "n = camera1.transform.position - transform.position;" variable?.
I have tried severals ways but I'm new to unity and scripting in it so my tries were probably wrong. If someone could give me an example of how i could write it, I would massively thankful.
this is the Code
var go = GameObject.Find("camera1");
var camera1 : Transform;
var camera2 : Transform;
function start()
{
}
function Update()
{
var n = camera1.transform.position - transform.position;
transform.rotation = Quaternion.LookRotation( n );
if (go.GetComponent(GUI_cam).count == 2)
{
//CAMERA 1 GOES HERE
}
if (go.GetComponent(GUI_cam).count == 3)
{
//CAMERA 2 GOES HERE
}
}
Comment
Answer by Loius · Apr 09, 2013 at 08:40 PM
var cam : Camera = (count==2?camera1:camera2);
A more easily extendable, readable solution would be:
var cameras : Camera[];
var cam : Camera = cameras[ GetComponent(GUI_cam).count-2 ];
Once you have cam just use that instead of camera1 or camera2.
Your answer
