You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.3 KiB
68 lines
1.3 KiB
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;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
foreach(var flake in SnowFlakes)
|
|
{
|
|
flake._snowFlakeBehaviour = this;
|
|
}
|
|
Play();
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
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());
|
|
}
|
|
|
|
}
|
|
|