- Home /
Cant pick up coin in Unity 2D
Hi. Im trying to pick up a coin with my Player, but i cant get it to work. using UnityEngine; using System.Collections; public class Coins : MonoBehaviour { void OnTriggerEnter2D(Collider2D col){ if (col.gameObject.tag == "Coin") { Destroy (col.gameObject); } } }
What happens. Can you elaborate it more. Are you passing right through the coins and nothing happens?
Right. Sounds silly, but,did you check your trigger to be an actual Trigger.
Look at 2D collider in your inspector panel and make sure the checkbox
"IsTrigger"
is checked. Sounds silly, almost always something like this for me when i first got started.
Also, in the Inspector panel, the Tag tab has the name
"Coin"
inside it to ensure that that the trigger is actually finding the object by its tag.
If you mean nothing happens when you pick up the coin try incrementing a money variable by one every time you pick up the coin. Just please be more specific on your problem if thats not the problem.
Answer by Moohasha · Jan 12, 2014 at 02:34 PM
Make sure both objectd havr a RigidBody2D or else Unity won't consider it when checking for collisions.
This was it. The coin was just a Sphere Collider. Not 2D. This should be obvious but im quite new to unity.
If answer was helpful, accept it as the correct one. Others deserve a thump up too in my opinion.
Your answer
Follow this Question
Related Questions
coin collecting with onscreen score 1 Answer
Picking up a coin in 2D 2 Answers
Shopping with GameCoins 0 Answers
how to use coin in menu and shop it just update only in level not working menu and shop 0 Answers
hit coin collider 2 Answers