public class ParticleTrigger : MonoBehaviour
{
[SerializeField]
ParticleSystem speedBoostParticle = null;
public void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
speedBoostParticle.Play();
}
}
}
Into this
public class ParticleTrigger : MonoBehaviour
{
[SerializeField]
ParticleSystem speedBoostParticle = null;
public void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("Player"))
{
speedBoostParticle.Play();
}
}
}
But for some reason the OnTriggerEnter thing does not work. Also a note the object which this script is on is destroyed 0.1 seconds after collision with player as it is a powerup pickup
Note: Both GameObjects must contain a Collider component. One must have Collider.isTrigger enabled, and contain a Rigidbody. If both GameObjects have Collider.isTrigger enabled, no collision happens. The same applies when both GameObjects do not have a Rigidbody component.
Why it Destroys its should come from an another script or if the particle system is on the same GameObject as this script. just use a different Stop Action on the particle system.
you find the options in a dropdown in the particle settings its propably set to Destroy… try none or Callback and destroy or reuse If you need.
Either one of the objects has to have Trigger collider and also a rigid body.
//Declare the particle effect game object and put it in the editor.
public GameObject effect_par;
//Inside the ontrigger
private void OnTriggerEnter2D(Collider2D col)
{
if (col.tag == "Player")
Instantiate(effect_par, transform.position, transform.rotation);
}