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/Epic Toon FX/Demo/Scripts/ETFXLoopScript.cs

49 lines
1.0 KiB
C#

3 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 spawnWithoutLight = true;
public bool spawnWithoutSound = true;
3 months ago
void Start ()
{
PlayEffect();
}
public void PlayEffect()
{
StartCoroutine("EffectLoop");
}
IEnumerator EffectLoop()
{
GameObject effectPlayer = (GameObject) Instantiate(chosenEffect, transform.position, transform.rotation);
if(spawnWithoutLight = true && effectPlayer.GetComponent<Light>())
3 months ago
{
effectPlayer.GetComponent<Light>().enabled = false;
//Destroy(gameObject.GetComponent<Light>());
3 months ago
}
if(spawnWithoutSound = true && effectPlayer.GetComponent<AudioSource>())
3 months ago
{
effectPlayer.GetComponent<AudioSource>().enabled = false;
//Destroy(gameObject.GetComponent<AudioSource>());
3 months ago
}
3 months ago
yield return new WaitForSeconds(loopTimeLimit);
Destroy (effectPlayer);
PlayEffect();
}
}
}