Idiot can't play a particle system onCollisionEnter
MAN I hate posting questions for which the answers are trivial, but I'm getting frustrated here. Here's me code:
public class HeroScript : MonoBehaviour
{
ParticleSystem myPartSys;
// Use this for initialization
void Start ()
{
myPartSys = GetComponent <ParticleSystem> ();
}
// Update is called once per frame
void Update ()
{
}
void OnCollisionEnter2D (Collision2D other)
{
myPartSys.enableEmission = true;
myPartSys.Play();
}
}
OOPS I left out
using UnityEngine; using System.Collections;
public class HeroScript : $$anonymous$$onoBehaviour { ParticleSystem myPartSys;
No errors, but it still won't play the particle system when I collide the other game object with the object the script is assigned to...
it's definitely getting to OnCollisionEnter2D()
?
Yeah, I'm sitting here repeatedly bringing the 2 objects together manually while in Play mode double and triple checking the collision. I'm having trouble in general with the ParticleSystem.Play methodology, whether to use myParSys.emission.enabled or myParSys.Play or myParSys.emission.enabled = true or myParSys.enableEmission = true or whatever the syntax should be... the online suggestions seem to vary between these
Answer by skillbow · Jan 05, 2016 at 04:14 PM
@bobmaxine This might be worth a try
ParticleSystem.EmissionModule myPartSys;
void Start () {
myPartSys = GetComponent<ParticleSystem>().emission;
}
void void OnCollisionEnter2D (Collision2D other) {
ParticleSystem.EmissionModule em = myPartSys;
em.enabled = true;
}
Answer by $$anonymous$$ · Jan 05, 2016 at 07:57 PM
Yeah sorry, I responded earlier but I guess it's not up yet... turns out I got it going with my above code (didn't need the "myPartSys.enableEmission = true;"), but had not realized I needed a rigidbody 2D specifically on the object with the above code.
I hate having such a simple question not only frustrate me but have you kind people spend your valuable time on. Thank you.
I was pulling my hair out on a similar one just the other day. Glad you got it sorted.