I’m making a zombie game and I want to make it so that if a bullet Object collides with the zombie Object, the zombie object disappears. This script will be attached to the bullet, but if it has to be attached to the zombie, please say so.
thanks!
I’m making a zombie game and I want to make it so that if a bullet Object collides with the zombie Object, the zombie object disappears. This script will be attached to the bullet, but if it has to be attached to the zombie, please say so.
thanks!
As long as both have a collider you you should be able to do the script on either.
Use the onCollisionEnter function, check the docs for usages.
Create some tags, google how to do that too. Maybe make 2, 1 called Zombie and the other called Bullet. Add those tags to their respective objects.
Then in your collision function you can check if the thing it collided with is a certain tag. Like: collision.gameObject.tag == “Zombie”. Use the tags because the collision function will happen when the zombie touches the floor or the player too.
If that’s true then you know one has hit the other then simply use a destroy function on them both. I think the order matters like if the script is in the zombie, destroy the bullet before the zombie because then the script will be destroyed before it destroys the bullet.
Have fun!