You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/3rd/Epic Toon FX/Demo/Scripts/ETFXLoopScript.cs

46 lines
922 B
C#

2 months ago
using UnityEngine;
using System.Collections;
namespace EpicToonFX
{
public class ETFXLoopScript : MonoBehaviour
{
public GameObject chosenEffect;
public float loopTimeLimit = 2.0f;
[Header("Spawn without")]
public bool disableLights = true;
public bool disableSound = true;
void Start ()
{
PlayEffect();
}
public void PlayEffect()
{
StartCoroutine("EffectLoop");
}
IEnumerator EffectLoop()
{
GameObject effectPlayer = (GameObject) Instantiate(chosenEffect, transform.position, transform.rotation);
if (disableLights && effectPlayer.GetComponent<Light>())
{
effectPlayer.GetComponent<Light>().enabled = false;
}
if (disableSound && effectPlayer.GetComponent<AudioSource>())
{
effectPlayer.GetComponent<AudioSource>().enabled = false;
}
yield return new WaitForSeconds(loopTimeLimit);
Destroy (effectPlayer);
PlayEffect();
}
}
}