2 using System.Collections;
4 using Random = UnityEngine.Random;
6 public class Spotlight : MonoBehaviour
8 [SerializeField] private int duration;
9 [SerializeField] private float speed;
10 private Vector2 targetPosition;
14 StartCoroutine(RandomMove());
17 private void FixedUpdate()
19 var target = new Vector3(targetPosition.x, targetPosition.y, transform.position.z);
20 if (transform.position == Vector3.zero)
21 transform.position = target;
23 transform.position = Vector3.MoveTowards(transform.position, target, Time.deltaTime * speed);
26 private IEnumerator RandomMove()
28 for (var i = 0; i < duration; i++)
30 targetPosition = new Vector2(Random.Range(-12f, 12f), Random.Range(3.5f, 6.2f));
31 yield return new WaitForSeconds(.8f);