This script is for a overhead spotlight that is a child of a gameobject that is suppose to stimulate a searchlight. The rotation works perfectly the first time but, it will not rotate thereafter. i have a feeling it might have something to do with the “random.range” part pulling from the same seed value but other than that im out of ideas.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpotlightController : MonoBehaviour {
private IEnumerator Start()
{
while (Application.isPlaying) {
Quaternion randomRot = Quaternion.Euler (Random.Range (-10, 10), Random.Range (-20, 20), 0f);
while(Vector3.Distance(this.transform.root.localEulerAngles, randomRot.eulerAngles) > .1f)
{
this.transform.localRotation = Quaternion.Lerp(this.transform.localRotation, randomRot, Time.deltaTime);
yield return null;
}
yield return new WaitForSeconds(1f);
}
}