- Home /
Problem is not reproducible or outdated
function OnCollissionEnter not working
I am trying to make a pickup script in which when the player collides with the object the object gets destroyed.But this does not seems to work.Please help.
var player : Transform; function OnCollissionEnter(info : Collision ) { if(info.gameObject.name == "player") { Destroy (gameObject); } }
Please use the code tag when writing code (the 101 010 button)
Answer by tanoshimi · Jun 12, 2014 at 05:08 PM
It's OnCollisionEnter() <-- one "s"
function OnCollisionEnter(info : Collision)
{
if(info.gameObject.tag == "player")
{
Destroy(gameObject, 1);
}
}
this is the script.The script is still not working please help
"Not working" is not a sufficient description for anyone to help you. What happens? Error message? Does the method get called at all? Does the player have a rigid body and collider component attached, and are they tagged "player"?
Drop the info. Tags are case sensitive. $$anonymous$$ake sure the player is tagged properly. Also check there are colliders on both objects and a rigidbody on at least one of them.
thanks for replying but ins$$anonymous$$d of using OnCollisionEnter() i used OnControllerColliderHit(hit: ControllerColliderHit) and tagged the ammo box with box and now it works. Thanks for trying to help me.
Follow this Question
Related Questions
Use editor icons in game? 2 Answers
How to respawn items along with player 1 Answer
Check Colliders in X or Y axis separately 0 Answers
Trying to destoy an object can a transform be hardcoded? 2 Answers
Item collection in specific sequence. 2 Answers