#it is part of the bullet prefab and Play
1 messages · Page 1 of 1 (latest)
yes
but it is destroying correctly?
it is destroying the bullet correctly
ok that's weird
ok
can you show the code for explode?
so I forgot to untick the play on awake
sure
private void explode()
{
if (!explosion.GetComponent<ParticleSystem>().isPlaying)
{
explosion.GetComponent<ParticleSystem>().Play();
}
}
ah
well, at least you found it out 😆
now it does not play at start but still does not play on collision
try removing your first condition
or put Debug.Log just after to check if it enters the condition
the if?
private void explode()
{
if (!explosion.GetComponent<ParticleSystem>().isPlaying)
{
Debug.Log("Enter Condition");
explosion.GetComponent<ParticleSystem>().Play();
}
}```
ok let me see
now i'm not super fluent on the particle system it seems to have its quirks
yes, yes it does
okay so it's really the play function that has a problem somehow
so it has to do
ah sorry
with the way it's attached as a component or on your prefab
i'm under the feeling it's getting messed up by the instantiations
perhaps
I will double check its properties
beacuse I have another particle for the player and the code is pretty much the same for it but it works fine
then agai the player is not instantiated so....
also always double condition with && thingie.GetComponent<T>() != null
it helps you debug if the component got lost or anything abnormal is going on
You can also just add a script on the bullet and check for a collision. If it hits a gameobject, instantiate the explosion
yeah i'd do it from outside tbh
but i understand the handiness of having it on a prefab
You can also do it the other way around, and have a script on the object and check if a bullet hits it, if so instantiate an explosion on the bullets transform
i guess that depends if it should explode when colliding on anything or just these specific targets
yea
cute snek btw 🙂
if you want it to explode on multiple different things you should just add the script on the bullets
cute herpeto thingies, ha 😂
yeah I thought about it but I want the effect to be on the place where the bullet hit
if the bullet hits the cornet and the explosion plays in the middle it won't look good
Just get the transform of the bullet when it hits
Let me write an example
there is thing called ContactPoint in unity but it was too complicated for something so basic
Here's a script that's supposed to be on the object thats being shot at: ```c
public void OnCollisionEnter(collision col){
if(col.CompareTag("bullet")){ //Make sure you have a bullet tag on the bullet
// Instantiate explosion
Destroy()
}
}
I just need to make the particle work and it would be fine
You can then instantiate the explosion, and then destroy the object
yeah I tried that at first and it was fine but unity kept giving me an annoying yet non fatal error
What was the error?
uhh...
wait no that was for something else
lemme do that again actually
hold up
😑
yeah that worked but now I got explosion game objects that just stay
like how do I kill them now
Can you share a ss? I dont understand what you mean
You need to turn looping off, on the particle
it is off
Can you share a screenshot of the inspector of the animation and of the problem?
Ohh I see
they play on the bullet collision which is fine they do not play afterwards
and just stay there
Yea you need to destroy those too
wait
You should just be able to Destroy() the explosion as well
yea
that would work
just make sure you destroy it once the animation has completely finished
something like this
in the OnCollisionEnter
when the bullet collides