using System.Collections; using System.Collections.Generic; using UnityEngine; public class SnowFlakeBehaviour : MonoBehaviour { [AutoUI] public Vector2 Position; [AutoUI] public float DisappearTime = 5; [AutoUI] public float DisappearTimeRandomRange = 2; public SnowFlake[] SnowFlakes; [SerializeField] private SnowFlake _currentFlake; private RectTransform _rectTransform; // Start is called before the first frame update void Start() { foreach(var flake in SnowFlakes) { flake._snowFlakeBehaviour = this; } Play(); _rectTransform = GetComponent(); } // Update is called once per frame void Update() { if((Time.frameCount & 0x19) == 0) _rectTransform.anchoredPosition = Position; } IEnumerator WaitToPlay() { float waitTime = DisappearTime + Random.Range(-DisappearTimeRandomRange, DisappearTimeRandomRange) / 2.0f; waitTime = Mathf.Max(0, waitTime); Debug.Log(waitTime); yield return new WaitForSeconds(waitTime); Play(); } public void Play() { _currentFlake = SnowFlakes[Random.Range(0, SnowFlakes.Length)]; Debug.Log(_currentFlake.gameObject.name); _currentFlake.Play(); } public void Trigger() { _currentFlake.Trigger(); } public void ResetFlake() { StartCoroutine(WaitToPlay()); } }