Collecting items
Hi everyone! The character in my 2D game has to collect some objects(Coins) for points and the scripts works nice. What can I add to the scripts if there are 2 or more types of collectible items (F/ex: coins for 1 point, and diamonds for 5points and etc.)? Do I have to use void OnTriggerEnter2D twice or more?
Change the value of the points you add. Do not add multiple OnTriggerEnter they will not work. For more help post the code.
Answer by hexagonius · Mar 27, 2017 at 01:47 PM
OnTriggerEnter just informs about each and every trigger overlap allowed according to the layers involved. If you want to distinguish between objects there are multiple ways in achieving it:
- assign different tags to the different pickups and use CompareTag
to check which one it is
- call GetComponent for a specific script and check for null if the script exists. Each pickup could have a different scrip on them
- the script on the pickups could be identical, but there could be a property in the script that differentates them
- they could have different names...
You have quite a few options. But bottom line is: Use OnTriggerEnter(Collider col)
once
Your answer
Follow this Question
Related Questions
Help with coin pick up script 1 Answer
Finding Boundaries of a Cover Object 1 Answer
[2D Game] My coins won't disappear when touched,My coins won't disappear in my 2D game 1 Answer
How do I make the player carry an object once they have collected it? 2 Answers
How do i Instantiate sub-Points with in Multiple Points?? 0 Answers