Your script there is a script not for the bullet, but for your player. The OnCollisionEnter function is called when whatever the script is attached to collides. If you want that function called when the bullet collides, you need that script attached to the bullet. Create a new script with that function, and attach it to…
the null references are because the new script has a bunch of stuff it doesn't need to just destroy the bullet (it's actually trying to create another bullet as soon as it's spawned, most likely, because you still have that code in the update function of the bullet collision script). instead, keep the bullet shooting…
Ok well I for my player script I don't have that OnCollisionEnter function and On my new Script for my bullet I have this. function Start () { } function Update () { } function OnCollisionEnter(c:Collision) { if(c.gameObject.name == "Bullet_Prefab") { Destroy(c.gameObject); } } But it still won't destroy and I can't figure…
If you want to destroy the bullet on collision, make sure it is a rigidbody. Make script, attach to the bullet object and put this in there... function OnCollisionEnter() { Destroy (gameObject); }
You nearly got it. Delete this part, because it doesn't do what you are looking for. The OnCollosionEnter function does not return the collider of your bullet. It returns the collider of the object that the object with the attached script just entered!
+1 Larmont don't forget to add collider to your bullet for that snipet to work.. If your bullets move too quickly it could be worth to expand shooting script with raycasting to actualy get impact point in advance and calculate timed destruction in advance..
Ok I followed what you said my script now looks like this function Start () { } function Update () { } function OnCollisionEnter(c:Collision) { Destroy(c.gameObject); } But whatever the bullet touches it destroys. For ex: I shoot cube, cube gets destroyed. What would I write so that bullet gets destroyed if it collides?
Learn to program, I don't wanna sound like a dick but no-one else is saying it so I will. You're having way too many problems with way too basic of a script and you seem to be blindly doing what we say rather than understanding what we're telling you. So sit yourself down, and learn to program. If you're doing this to…