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…
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…
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?
Hey everybody I'm just trying to have my bullet destroy on impact. My bullet is a prefab. Here is my unity screen Here is my code: public var prefabBullet:Transform; //object to create public var bulletSpawnPoint:Transform; //place to create object public var shootForce:float; //speed of object function Start () { }…
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); }
Ok so I made the my "Bullet" (Prefab) a gameobject and I attached my code to the gameobject Here is my code: #pragma strict public var prefabBullet:Transform; //object to create public var bulletSpawnPoint:Transform; //place to create object public var shootForce:float; //speed of object function Start () { } function…
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 that part worked fine, thanks Lamont and cupsster. Now I need the bullet to destroy after a certain amount of time if the bullet hits nothing. I seriously can't remember the functions :(
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!
Well you should probably use unitys static Time class instead of creating a dedicated timer instance, look at the documentation. Also if you look at the documentation for the Destroy function you might find something very useful.