]> git.cameronkatri.com Git - gmtk-gamejam.git/blob - Assets/Scripts/Spotlight.cs
Add VFX
[gmtk-gamejam.git] / Assets / Scripts / Spotlight.cs
1 using System;
2 using System.Collections;
3 using UnityEngine;
4 using Random = UnityEngine.Random;
5
6 public class Spotlight : MonoBehaviour
7 {
8 [SerializeField] private int duration;
9 [SerializeField] private float speed;
10 private Vector2 targetPosition;
11
12 private void Start()
13 {
14 StartCoroutine(RandomMove());
15 }
16
17 private void FixedUpdate()
18 {
19 var target = new Vector3(targetPosition.x, targetPosition.y, transform.position.z);
20 if (transform.position == Vector3.zero)
21 transform.position = target;
22 else
23 transform.position = Vector3.MoveTowards(transform.position, target, Time.deltaTime * speed);
24 }
25
26 private IEnumerator RandomMove()
27 {
28 for (var i = 0; i < duration; i++)
29 {
30 targetPosition = new Vector2(Random.Range(-12f, 12f), Random.Range(3.5f, 6.2f));
31 yield return new WaitForSeconds(.8f);
32 }
33 Destroy(gameObject);
34 }
35 }