- Home /
Question by
Darktower121 · Sep 16, 2020 at 07:58 PM ·
scripting problemcoroutineint
Trying to trigger a function on another script 1 time, with an Int involved. PlsHelp
Basically when the score hits 1 i want to call a function that starts a Coroutine on another script. I can trigger the Coroutine just fine but it won't stop calling it because one of the triggers to call the Coroutine is the int score which is still 1 so it just repeatedly calls it every second and unity goes boom. I've added a bool like I've used to stop calls from looping but it doesnt do anything to help. Any insight would be greatly appreciated. Newish to coding, newish to unity.
public class ScoreTracker : MonoBehaviour
{
public int score;
public GameObject goalRefrence;
public static ScoreTracker instance;
public TextMeshProUGUI scoreText;
public GameObject windRefrence;
bool limitter;
void Start()
{
if (instance == null)
{
instance = this;
}
windRefrence.GetComponent<DropBall>();
}
public void Scorer(int goalPoint)
{
score += goalPoint;
scoreText.text = "" + score.ToString();
}
private void Update()
{
if (score == 1 && limitter == true)
{
limitter = false;
windRefrence.GetComponent<DropBall>().TriggerWindfall();
}
}
}
Comment