- Home /
Need Status from other Script
Hello,
I´ve Lights which are controlled by a script (light.js). Now i have a collider infront of the lights (called LightTrigger). Every time a gameobject enters this trigger it should react on the light, which you can see, at the moment.
So, i need for my LightTrigger.js the information which light is enabled (from the light.js.). I´ve tried this:
private var lightStatus = GameObject.Find(LightTrigger);
function Update ()
{
lightStatus = GetComponent(light);
}
function OnTriggerEnter (other : Collider)
{ if (green.enabled = true)
Destroy(other.gameObject);
}
lightStatus = GetComponent(light);
Does it finds the GameObject with the light.js by itself?
Answer by Eric5h5 · Dec 14, 2012 at 06:49 AM
You've implicitly defined lightStatus as a GameObject since you used GameObject.Find to declare it (not really a good idea by the way; you should stick to declaring variables outside code only, and run actual code such as Find inside functions). But then you try to redefine lightStatus as "light" inside Update (also not a good idea, just do GetComponent once instead of every frame), which you can't do. So it should be
private var lightStatus : light;
function Start() {
lightStatus = GetComponent(light);
}
Also I'd recommend using some other name for that variable aside from "lightStatus" since that's not accurately describing what that variable is. "lightScript" would be better.