From 65975146e07e33aa5cf5de83bee76c537ba787e3 Mon Sep 17 00:00:00 2001 From: Carson Katri Date: Sun, 13 Jun 2021 13:14:23 -0400 Subject: Add VFX --- Assets/Scripts/Spotlight.cs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Assets/Scripts/Spotlight.cs (limited to 'Assets/Scripts/Spotlight.cs') diff --git a/Assets/Scripts/Spotlight.cs b/Assets/Scripts/Spotlight.cs new file mode 100644 index 0000000..95a0f5e --- /dev/null +++ b/Assets/Scripts/Spotlight.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections; +using UnityEngine; +using Random = UnityEngine.Random; + +public class Spotlight : MonoBehaviour +{ + [SerializeField] private int duration; + [SerializeField] private float speed; + private Vector2 targetPosition; + + private void Start() + { + StartCoroutine(RandomMove()); + } + + private void FixedUpdate() + { + var target = new Vector3(targetPosition.x, targetPosition.y, transform.position.z); + if (transform.position == Vector3.zero) + transform.position = target; + else + transform.position = Vector3.MoveTowards(transform.position, target, Time.deltaTime * speed); + } + + private IEnumerator RandomMove() + { + for (var i = 0; i < duration; i++) + { + targetPosition = new Vector2(Random.Range(-12f, 12f), Random.Range(3.5f, 6.2f)); + yield return new WaitForSeconds(.8f); + } + Destroy(gameObject); + } +} -- cgit v1.2.3-56-ge451