I tried posting a couple times yesterday and it wasn’t working for me, so I’ll keep this simple and brief.
I want to fire a bullet, so instantiate - apply force - destroy on collision.
How would you code this? I’m stuck on the OnCollisionEnter Destroy part, I’m a n00b too fyi.
This and this video will answer everything you asked.
Thanks for the links :]
He didn’t cover the part I’m stuck on tho, I want to destroy the instanced bullet on collision, as aposed to after a length of time like the tutorial did.
Ima try writing a separate script for the bullet prefab with an OnCollisionEnter function, I was previously tryna shove that function somewhere on my fire script which is attached to the camera, it never occurred to me to make it a separate component, thanks for your help :]
Ok so I wrote this lil script and attatched it to the bullet prefab, and I get this error when I run the game (also the instanced bullets are not destroying themselves on collision)
Assets/CollDestroy.js(4,16): BCE0023: No appropriate version of ‘UnityEngine.Object.Destroy’ for the argument list ‘(System.Type)’ was found.
Here’s the code
function OnCollisionEnter (collision : Collision)
{
Destroy(GameObject);
}
Also, if I change the G in GameObject to a lowercase g, the prefab doesn’t seem to spawn at all :S
Ah ok I get it now, the correct way to write it was with the lowercase g of GameObject, and it was colliding with itself, so I created an empty, offset it from the camera and attached my shoot script to that :]