Hey o. New to unity and have a newbie question. The following code is supposed to add to a player score whenever a ball enters a box. However, whenever a ball enters a box, the score just gets replaced. For example, if the score is 25, when the ball falls into the 10 point box, the score is set to 10 instead of 35. I’m using countNumber to set the score for each box in the inspector.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Counter : MonoBehaviour
{
public Text CounterText;
private int Count = 0;
public int countNumber;
private void Start()
{
Count = 0;
}
private void OnTriggerEnter(Collider other)
{
Count += countNumber;
CounterText.text = "Count : " + Count;
Debug.Log("Score is: " + Count);
}
}