So I’m getting the error : InvalidCastException: Cannot cast from source type to destination type.
I suspect it might have something to do with gameObjects vs Transforms.
I’m still a little bit fuzzy on the difference between the two and was hoping someone could help me out and see what the error is here?
It occurs when distancetonext is first referenced.
#pragma strict
var respawnPoints : Transform;
var points : List.<Transform>;
var numberofnextrespawnpoint : int = 1;
function Start () {
points = new List.<Transform>(respawnPoints.GetComponentsInChildren.<Transform>()) ;
pointOfRespawn = 'RespawnPoint1';
**(ERROR RIGHT HERE)** distancetonext = Vector3.Distance (transform.position, GameObject.Find(pointOfRespawn).transform.position);
nextPointofRespawn = 'RespawnPoint1';
}
function Update () {
if (pointOfRespawn == 'RespawnPoint1'){
numberofnextrespawnpoint = 0;
}
else{
numberofnextrespawnpoint = points.IndexOf(GameObject.Find(pointOfRespawn).transform) + 1;
}
if (numberofnextrespawnpoint > points.Count){
numberofnextrespawnpoint = 0;
}
print(points[numberofnextrespawnpoint]);
nextPointofRespawn = points[numberofnextrespawnpoint].gameObject;
distancetonext = Vector3.Distance (transform.position, GameObject.Find(nextPointofRespawn).transform.position);
respawnPointNumber = numberofnextrespawnpoint;
}