- Home /
Question by
DaneleRoux · Apr 29, 2019 at 08:27 AM ·
raycastdestroyparticlesystemdestroygameobjectparticleeffect
Playing particle on 1 instance of cloned prefab
Hi there,
I have a spawner for a balloon prefab that spawn balloons on a timer.
My prefab script has a 'pop' particle slot that I set via the inspector.
The idea is that if I click on the balloon prefab, it must play the particle on the clicked balloon, and destroy the clicked gameobject, but not the others on the screen.
Right now, I have it working so that it does destroy the clicked balloon (working as intended), but the particle plays for all spawned gameobjects on the screen, not just the one I clicked.
Here is my variable and click to destroy function:
public ParticleSystem PopParticle;
// ==== Destroy balloon onclick
void PopBalloon() {
if (Input.GetMouseButtonDown(0)) {
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit)) {
CapsuleCollider capCollider = hit.collider as CapsuleCollider;
if (capCollider != null) {
ParticleSystem popEffect = Instantiate(PopParticle) as ParticleSystem;
popEffect.transform.position = transform.position;
popEffect.Play();
Destroy(capCollider.gameObject);
}
}
}
}// PopBalloon ends
How do I go about playing the particle only for the balloon that is being hit by the mouseclick?
Thanks in advance.
Dan
Comment