50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class CloudAnimation : MonoBehaviour
|
|
{
|
|
[System.Serializable]
|
|
public class Properties
|
|
{
|
|
public float fadeInTime = 1;
|
|
public float stayTime = 1;
|
|
public float fadeOutTime = 1;
|
|
public float speed = 1;
|
|
}
|
|
CanvasGroup canvasGroup;
|
|
public Properties properties;
|
|
private Coroutine coroutine;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
canvasGroup = GetComponent<CanvasGroup>();
|
|
coroutine = StartCoroutine(AnimateCloud());
|
|
}
|
|
|
|
public void Kill()
|
|
{
|
|
StopCoroutine(coroutine);
|
|
StartCoroutine(KillCloud());
|
|
}
|
|
IEnumerator AnimateCloud()
|
|
{
|
|
|
|
canvasGroup.alpha = 0;
|
|
yield return canvasGroup.FadeTo(1, properties.fadeInTime);
|
|
yield return new WaitForSeconds(properties.stayTime);
|
|
yield return KillCloud();
|
|
}
|
|
IEnumerator KillCloud()
|
|
{
|
|
yield return canvasGroup.FadeTo(0, properties.fadeOutTime);
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
transform.position += properties.speed * Time.deltaTime * Vector3.left * Camera.main.orthographicSize;
|
|
}
|
|
}
|