system
August 27, 2010, 10:53am
1
how do I change the "Target" in this script;
function Update ()
{
var Target = //what to do?;
transform.LookAt(Target);
}
through this script;
function OnTriggerEnter (myTrigger : Collider)
{
if(myTrigger.gameObject.tag == "enemy")
{
transform.Find("Turret Top");
}
}
the Hierarchy is like this;
Turret >> Range >> TurretTop
the first script is applied to Turret Top and the second to Range.
really can't work out what to do.
Move your 'var Target' outside the Update function to make it globally visible, and force the desired type:
var Target:transform;
Then you can use something like
transform.Find("Turret Top").GetComponent(NameOfYourFirstScript).Target=myTrigger.transform
Note you might want to do the transform.Find("Turret Top").GetComponent(NameOfYourFirstScript) part in Start() and store it in another var, and then just use that var in OnTriggerEnter, for performance reasons.
See this page in the documentation on how to make components on different game objects "talk" together:
http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Game_Objects.html