using System.Collections; using System.Collections.Generic; using UnityEngine; public class WellController : MonoBehaviour { public GameObject node; public int numberOfNodes = 5; private List nodes = new List(); public float spawnDelay; public float despawnTime; private Transform player; public float rightDistance = 0.2f; //Distance between spawned nodes public float maxUp = 0.2f; //Maximum up shift between orbs public float minDown = -0.2f; //Same but for down private Vector3 right; private Vector3 up; private void Awake() { } public void StartMinigame() { player = GameObject.FindGameObjectWithTag("MainCamera").transform; Vector3 nodeSpawn = player.transform.position + (player.forward * 0.5f); nodeSpawn.y = player.transform.position.y; up = player.transform.up; right = player.transform.right; StartCoroutine(SpawnNode(nodeSpawn, 0.5f, 0)); } IEnumerator SpawnNode(Vector3 nodeSpawn, float pitch, int i) { if(i == numberOfNodes) { yield return new WaitForSeconds((despawnTime - spawnDelay) * 2); //Wait for all of the nodes to despawn foreach(GameObject node in nodes) { node.GetComponent().FollowPlayer(); } nodes.Clear(); yield break; } GameObject tempNode = Instantiate(node, nodeSpawn, Quaternion.identity); tempNode.GetComponent().SetTimer(2f); tempNode.GetComponent().pitch = pitch; nodeSpawn = nodeSpawn + right * rightDistance + Random.Range(minDown, maxUp) * up; yield return new WaitForSeconds(spawnDelay); StartCoroutine(SpawnNode(nodeSpawn, pitch, i + 1)); yield return new WaitForSeconds(despawnTime - spawnDelay); if (tempNode.GetComponent().isTouched) { nodes.Add(tempNode); } } private void Update() { transform.Rotate(new Vector3(10f, 10f, 10f) * Time.deltaTime); } }