I have a script attached to one game object that grabs a script on another game object:
function Start() {
_healthScript = _healthMeter.GetComponent( "HealthScript" ) as HealthScript;
}
This doesn’t manage to grab the HealthScript from the game object for this particular object but works for others. If I add the following Update() it is able to grab it.
function Update () {
if( _healthScript == null ) {
_healthScript = _healthMeter.GetComponent( "HealthScript" )
as HealthScript;
}
}
So it looks like it’s a problem with the order in which the Start() runs as compared to when components get attached. Is there a better way to grab a script off a game object? Is there a different function that executes always after all the game objects have added their components?
Thanks for your help,
Rick