I wrote script that if my car hit light another object will get component Rigidbody. now about my problem: i want that if my car hit ANYTHING another object would get component Rigidbody. there is my script:
var bumper : GameObject;
function OnCollisionEnter(hit : Collision) {
if(hit.gameObject.tag == "light"){
bumper.AddComponent(Rigidbody).gameObject.tag == "bumper";
print("hit");
}
}
If you currently put the Rigidbody on “bumper” only if you hit something with the “light” tag, but now you want to add a rigidbody for any collision, simply remove your “if” statement that checks for the “light” tag:
var bumper : GameObject;
function OnCollisionEnter(hit : Collision) {
bumper.AddComponent(Rigidbody);
print("hit");
}
}
Also, not sure what you are trying to achieve with “gameObject.tag == “bumper”” - the “==” operator is for comparison, so it will return a true or false value, it won’t assign “bumper” to the tag variable.