- Home /
Object not being destroyed when shot
Hello,
At the moment I currently have a cube named Enemy which is following an animation (basically going in a straight line towards the camera) I also have a first person camera in with a gun and bullet etc.
I have this code that when the bullet hits the cube it should be destroyed but at the moment it's just going straight through them and sometimes 1 bullet bounces off the cube. On the cubes I have a Box Colder and the mesh filter.
function OnCollisionEnter(collision : Collision)
{
if(collision.gameObject.tag == "Enemy")
{
Destroy(gameObject);
Destroy(collision.gameObject);
}
}
Here is the code, am I missing anything such as a rigidbody etc?
Do a Debug.Log stating that the player or the enemy has been collided with a bullet.
If that's not working, make sure both the bullet and the enemy have a rigidbody on it.
Your answer
Follow this Question
Related Questions
Only one of all my Enemies shoots, Help please. 1 Answer
My project kicks me every time I destroy a block 0 Answers
destroy ''fireball'' on collision 1 Answer
My ship destroyed when i press fire 1 Answer
Score When Ship Bullet Hits An Enemy 1 Answer