Something obviously isn’t working, my point is, if you collect 3 “red coins” then unity will display the following text "You Lose!. It is working if you reach the score limit, or the specified amount of score i set up in the code. Here it is. I have already made the tag named “Red” for the red coin, and yet again it isn’t doing what it’s supposed to do.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour
{
public Text winText;
public static GameManager instance = null;
public GameObject scoreTextObject;
public GameObject youWinText;
public float resetDelay;
int score;
Text scoreText;
private int Red;
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Red"))
{
other.gameObject.SetActive(false);
Red = Red + 1;
}
if (Red == 3)
{
winText.text = "You lose!";
SceneManager.LoadScene("Level 1");
}
}
void Awake ()
{
if (instance == null)
instance = this;
else if (instance != null)
Destroy(gameObject);
scoreText = scoreTextObject.GetComponent<Text> ();
scoreText.text = "Current Score: " + score.ToString ();
winText.text = "";
}
public void Collect(int passedValue, GameObject passedObject)
{
passedObject.GetComponent<Renderer> ().enabled = false;
Destroy (passedObject, 1.0f);
score = score + passedValue;
scoreText.text = "Current Score: " + score.ToString ();
if (score >= 2550)
{
winText.text = "You Win!";
SceneManager.LoadScene("Level 2");
}
}
}