How can I add a number only once, and not continually?

4 days ago 8
ARTICLE AD BOX

Firstly, you can create method Hit() where you add points to general score. You can call it on Collider.OnCollisionEnter.

Secondly, you can create a data class which would represent a ball type. I see that you have balls of different colours. You can do:

public enum BallColor{ Red, Green } [Serializable] public class BallData{ public BallColor color, public int points }

And in your MonoBehavior class you can do:

[SerializeField] private List<BallData> ballsConfig;

Later you can access this data like this

var score = ballsConfig[0].score; var greenScore = ballsConfig.Find(ball => ball.color == BallColor.Green).score;

I'm not sure how your code works. It's not clear from the snippet you shared. Maybe I can help if you provide more info.

Anastasiia's user avatar

New contributor

Anastasiia is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Read Entire Article