So I am finally starting to get the hang of scripting in Unity. However, I’m still not perfect and I have recently made a script that dosen’t work and I can’t seem to find the flaw.
Here’s the script :
var Area1 : Transform;
var Area2 : Transform;
var MovePls : boolean = true;
var CurrentArea = 1;
function Start () {
gameObject.transform.position = Area1.transform.position;
}
function WaitSeconds () {
var randomWait = Random.Range(0, 6);
yield WaitForSeconds(randomWait);
MovePls = true;
}
function Update () {
if (MovePls)
if (CurrentArea == 1)
gameObject.transform.position = Area2.transform.position;
CurrentArea = 2;
if (CurrentArea == 2)
gameObject.transform.position = Area1.transform.position;
CurrentArea = 1;
}
Basically what it’s supposed to do is to take the object it’s attached to and first teleport it to “Area 1”, then wait randomly between 0 to 6 seconds and teleport it to “Area2”, then once again wait 0 to 6 seconds and teleport it back to*“Area 1”*, cycle repeats. However, the script dosen’t seem to work properly and I can’t find out what’s wrong since I’m still a noob.
Can someone experienced tell me what’s wrong with the script?