I’ve been making a very simple “slender” type game. All it is, is a sprite following the player. I want it so when the sprite (named The Creature) gets to close to the player, It teleports back to one of three locations. I want the choice of this location to be randomized. I already made 3 empty game objects for the spawn and have made transform variables for each of them. I’m very new to this coding, I’ve used unity itself plenty. I’ve looked everywhere and cannot find a situation similar enough to mine for me to figure it out. Thanks in advance for any help.
(Java script)
var respawnA : Transform;
var respawnB : Transform;
var respawnC : Transform;
var speed : float = 5; //speed of movement
var Target: Transform; //the player it's chasing.
var RespawnArray = new Array("respawnA", "respawnB", "respawnC"); //each of the spawns
function Start () {
}
function Update () {
var MyIndex = Random.Range(0, RespawnArray.length); // the pick of spawns
transform.LookAt (Target); //look at the player
transform.Translate (Vector3.forward * speed * Time.deltaTime); //move at the player
if (Vector3.Distance(transform.position, Target.position) < 1)// when it gets too close, teleport
transform.position = MyIndex.position; //the location of that spawn.
}
The game runs until the creature gets too close. then it just sticks to the player and spams the console error "MissingFieldException: System.Int32.position
Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.FindExtension (IEnumerable`1 candidates)
Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.Create (SetOrGet gos)
Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.CreateGetter ()
Boo.Lang.Runtime.RuntimeServices.DoCreatePropGetDispatcher (System.Object target, System.Type type, System.String name)
Boo.Lang.Runtime.RuntimeServices.CreatePropGetDispatcher (System.Object target, System.String name)
Boo.Lang.Runtime.RuntimeServices+c__AnonStorey17.<>m__C ()
Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.DispatcherKey key, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[ ] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[ ] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetProperty (System.Object target, System.String name)
UnityScript.Lang.UnityRuntimeServices.GetProperty (System.Object target, System.String name)
"