I’ve been trying to figure out why this is but I just can’t put my finger on it. I have a C# script the moves my game object around randomly and pauses for about a second before moving again but every time I start up the game the game object always reset to the middle of the screen instead of where I’ve moved it to. Any idea what’s wrong? Thanks in advance.
using UnityEngine;
using System.Collections;
public class RandomMotionScript : MonoBehaviour {
public bool waiting = false;
Vector3 randomPosition;
float moveDelay = 1.0F;
// Update is called once per frame
void Update () {
if (waiting == false)
{
SendMessage(“LerpCube”);
}
else
{
transform.position = Vector3.Lerp (transform.position, randomPosition, Time.deltaTime*1);
}
}
IEnumerator LerpCube()
{
randomPosition = new Vector3 (Random.Range (8,-8), Random.Range(8,-8));
waiting = true;
yield return new WaitForSeconds (moveDelay);
waiting = false;
}
}