- Home /
Question by
TheCount · Dec 30, 2013 at 05:35 PM ·
javascriptarrayarraysdistance
Distance error: Cannot cast from source type to destination
Every time I run this code, I get a 'Cannot cast from source type to destination type'
The error occurs on last line where I'm figuring out distance to next.
none of the variables are null I just omitted some of them for sake of brevity.
Pleas help.
var nextPointofRespawn;
var numberofnextrespawnpoint : int = 1;
var points1 : GameObject[];
numberofnextrespawnpoint = findposinarr(points1, GameObject.Find(pointOfRespawn)) + 1;
if (numberofnextrespawnpoint > points1.Length){
numberofnextrespawnpoint = 0;
}
nextPointofRespawn = points1[numberofnextrespawnpoint].ToString;
distancetonext = Vector3.Distance (transform.position, GameObject.Find(nextPointofRespawn).transform.position);
Comment
Debug like this, check for any errors
nextPointofRespawn = points1[numberofnextrespawnpoint].ToString;
Debug.Log( nextPointofRespawn );
GameObject go = GameObject.Find(nextPointofRespawn );
if( go == null ) Debug.Log( "No game objects found for " + nextPointofRespawn );
else distancetonext = Vector3.Distance (transform.position, go.transform.position);
Alright.
I get
RespawnPoint1
and then I get
CompilerGenerated.AIScript2_place$callable0$133_56 UnityEngine.Debug:Log(Object)