i am VERY new to Unity and coding and i’m making my first game in which i’m trying to raise text value by 1 every time the player collides with an obstacle and the scene restarts. after many many hours i’m left with this code:
using UnityEngine;
using UnityEngine.UI;
public class Score : MonoBehaviour
{
public Collision collision;
public Transform player;
public Text score;
public int start = 0;
public int failCount;
private void Start()
{
failCount = start;
score.text = failCount.ToString();
}
private void OnCollisionEnter(UnityEngine.Collision collisioninfo)
{
if (collisioninfo.gameObject.tag == "Obstacle")
{
failCount += 1;
}
}
}
no errors but the code simply does nothing, but I’m also very stubborn and even though i will never do anything with this terrible game I still want to achieve what I have desired and I really wanted to figure it out on my own but i just can’t.