collision detection (New)

Hi sorry I tried searching the forum for a good example of what I am trying to do, but I didn’t find anything. I am trying to script everything out on my game without having to use the GUI because I plan on switching out the models later so I don’t want to attach too much to them.

So I have all my physics done and it is working as I intend it to. Now I want to have reactions on collision like sound or adjustments. I have looked at the documentation, but on the below script how does it determine what object it is detecting collision for? I figure it is probably because the script has to be attached to the model. Can I just do MODEL.addcomponent(SCRIPTNAME)?
Is there anyway to actually tell it what model we are checking for collision on so I can have 1 script with all my collision?

function OnCollisionEnter(collision : Collision) {
// Debug-draw all contact points and normals
for (var contact : ContactPoint in collision.contacts) {
Debug.DrawRay(contact.point, contact.normal, Color.white);
}

// Play a sound if the coliding objects had a big impact.
if (collision.relativeVelocity.magnitude > 2)
audio.Play();
}

also what is (collision : Collision)?
I know there is a collision class, but a lot of it is read only.

sorry if it s a dumb question. I want to avoid having scripts for each model and just have 1 script with all collision actions.

You don’t really want to do that (even if it was possible)…Unity is much easier when using it as designed.

Sounds to me like you need to look into how prefabs work. You can always switch out models without having to redo anything else.

–Eric

I’ll look into prefrabs, but one the real goal is to have a model loaded from the web. Hopefully I can do the same like that.

So It would be cool if I just create a collision script for each model and just have my main script add that component(script) to the model I decide. right?

That would work, although understanding prefabs is somewhat vital to understanding Unity.

–Eric