I want to interpolate A Game Object between random positions of Other Game Objects. Just Trying to get it take cover in random spots in the game. I’ve tried this but it only moves one tick.
using UnityEngine;
using System.Collections;
public class CoverIdentification : MonoBehaviour {
private GameObject[] cover = new GameObject[5];
private int n;
private bool switcher = false;
// Use this for initialization
void Start () {
cover = GameObject.FindGameObjectsWithTag ("cover");
}
void Update()
{
StartCoroutine (switching ());
}
IEnumerator switching()
{
if(switcher == false)
{
switcher = true;
n = Random.Range (0, cover.Length);
Debug.Log (n);
yield return new WaitForSeconds (3f);
transform.position = Vector3.Lerp (gameObject.transform.position, cover [n].transform.position,Time.deltaTime);
yield return new WaitForSeconds (3f);
switcher = false;
}
}
}