I’m trying to make a particlesystem appear upon a collision and make it disappear after three seconds. Can I accomplish this using coroutines? The code I have so far (which doesn’t work) is:
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
public ParticleSystem ps;
private float amt = 3f;
// Use this for initialization
void Start () {
ps.renderer.enabled = false;
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter (Collider other) {
Destroy(this.gameObject);
ps.transform.position= new Vector3(this.transform.position.x,this.transform.position.y, this.transform.position.z);
ps.renderer.enabled = true;
StartCoroutine(pauser());
}
IEnumerator pauser()
{
yield return new WaitForSeconds(amt);
Destroy(ps.gameObject);
}
}