Reset score after death
Hello everyone. i created a game and i have a problem with scoring. i have 2 c# scripts for a little song and for scoring.
This is what i am talking about: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class colectezs : MonoBehaviour { public GameObject scoreText; public static int theScore;
void Update()
{
scoreText.GetComponent<Text>().text = " Special score " + theScore;
}
}
and
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class colectx2 : MonoBehaviour {
public AudioSource collectSound;
void OnTriggerEnter(Collider other)
{
collectSound.Play();
colectezs.theScore += 50;
Destroy(gameObject);
}
}
MY PROBLEM IS: When i die and i restart the game THE SCORE IS THE SAME AS I DIED. EXEMPLE: I die at 50 score. When i start the game i start not AT THE 0, i start at the 50 and this isn't good. I hope you can understand what i want to say. I think that my problem is about the STATIC INT theScore i have no idea how i am suppose to use theScore in the second script without static. Please help me. If you can write me the right way.
Your answer
![](https://koobas.hobune.stream/wayback/20220612211509im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can i get a scoring system? 1 Answer
How do I add a score system? 1 Answer
How do I randomly generate two obstacles in a 3D endless runner with 1 gap to go through? 1 Answer
How do I make the Score system work? 1 Answer
Object Reference not set to an instance of object / printing a variable from another scene 1 Answer