- Home /
Trigger Only For Player.
Hello, Seem to be having some trouble with a item pickup script, I intend to fly into a pickup item to pick the item up for the Player only. But any object that collides with it seems to pick it up for me, Help me out a little please?
function OnTriggerEnter(other : Collider)
{
if(other.collider.tag == Player.tag)
{
PickUpItem();
}
}
Answer by aldonaletto · Oct 12, 2013 at 12:55 AM
You must specify the tag, and assign the same tag to the player. If this function is in the trigger script, it should be like this:
function OnTriggerEnter(other : Collider)
{
if (other.tag == "Player") // remember to tag the player as "Player"
{
PickUpItem();
}
}
Your code also could work: set the player tag to "Player" in the Inspector. If the player is untagged, all other untagged objects (default) will pick the object for you.
Thanks for the help, changing if(other.collider.tag == Player.tag) to if (other.tag == "Player") Did the job.
Sorry i cannot seem to up-vote due to me not having 15 rep? Thanks again.
Your answer
Follow this Question
Related Questions
Internal collisions 1 Answer
Raycast on a 2D Collider 7 Answers
The Child Is Not Hovered When Passing The Parent's Collider 0 Answers
Character - what collider? 2 Answers
Performance: Addcomponent BoxCollider in update method 0 Answers