Making score counter subtract points when hitting obstacles
Hey guys, in my game I have scripted a score counter that gives you 1 point for every cube you fly through. On the map I made there are a few different obstacles that are supposed to subtract a point from the score counter if the player hits them. The Script I made for the cubes to add a point looks like this:
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Pick Up"))
{
other.gameObject.SetActive(false);
count = count + 1;
SetCountText();
}
}
Im not sure how to set this method for the obstacles since they are all different objects, please help!
Answer by Cooperall · Sep 07, 2019 at 09:17 PM
Hello! In order to make sure this function works, you need to make sure each one of your obstacles have a collider attached to them that are a trigger.
See this for more info: https://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html
Thank you so much, I totally forgot that and now it works!
Your answer

Follow this Question
Related Questions
How to Make Object Spin While Moving? 1 Answer
show canvas if score = 5 0 Answers
My player collides with a pickup but the score goes up for 2 not 1 0 Answers
How do I make scenes switch properly c# 0 Answers
I would like a score counter pls? 0 Answers