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?
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