- Home /
3 vector3 distance checks, only one works
hello there,
i have three objects (all exactly the same except the texture); they all have a script on them that measures the distance to the player and displays a gui texture when the player is near.
now all 3 scripts are exactly the same, but one of them works and the others don't. i even copied the working one into the other two - still, they won't do anything.
working code:
var Player : Transform;
private var dist : float;
function Update ()
{
dist = Vector3.Distance(transform.position, Player.position);
Debug.Log("distance from cogwheel: " +dist);
}
not working code:
var Player1 : Transform;
private var dist1 : float;
function Update ()
{
dist1 = Vector3.Distance(transform.position, Player1.position);
Debug.Log("distance from eastern: " +dist1);
}
the second code does not update the dist1 variable & the Debug Log from the update function does not return, so it has to be somewhere there (i think). if i try to return the value of dist1 later in the code it's '0'.
anyway, i'm running out of ideas. is it maybe not possible to do three different distance checks at the same time? should the distance check be on the player rather than the 3 objects?
Answer by almo · Jul 26, 2011 at 01:40 PM
Looks to me like the Update function in the second case is not being called. Are you sure the object this is on is enabled? Try Debug.Log("Update"); as the first line in the Update function as a baseline check.
i feel very stupid now.
yes, the object was enabled, but the script wasn't >.< so sorry for asking silly questions... but thank you very much for your help!