using UnityEngine;
using System.Collections;
public class GameManager : MonoBehaviour
{
#region variables
public const int MaxBrainGamesPerTunnel = 3;
#region static
public static float GameSpeed;
public static int BrainGamesPlayed = 0;
public static bool GameOver, IsGamePaused;
#endregion
public GameObject blackScreen;
public GameObject GameWorld;
#endregion
void Awake()
{
GameSpeed = 13 * PlayerPrefs.GetFloat("ScaleY"); //editor
BlackScreenManager.IsTotallyBlack = false;
//print(PlayerPrefs.GetInt("CameraWidth") + " " + PlayerPrefs.GetInt("CameraHeight"));
}
void Update () {
CheckForGameOver();
}
void CheckForGameOver()
{
if (GameOver)
{
blackScreen.SetActive(true);
GameSpeed *= 0.9f;
if (BlackScreenManager.IsTotallyBlack)
{
Destroy(GameWorld);
Application.LoadLevel("MainMenuScene");
}
}
}
void OnDestroy()
{
GameOver = false;
}
public static void PauseGame()
{
IsGamePaused = true;
}
public static void ResumeGame()
{
IsGamePaused = false;
}
}
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class CheckIsCorrect : MonoBehaviour {
public static bool CanPlay = true;
private GameObject currentText;
private float timePassedAfterClick;
public GameObject correct;
public GameObject incorrect;
void Start () {
this.currentText = GameObject.Find(transform.name + "Text");
CanPlay = false;
//print(GameManager.BrainGamesPlayed);
}
void Update () {
Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
this.timePassedAfterClick += (this.timePassedAfterClick > 0 ? Time.deltaTime : 0);
if (this.timePassedAfterClick == 0)
{
if (collider2D.OverlapPoint(mousePos) && Input.GetMouseButtonDown(0))
{
this.timePassedAfterClick += Time.deltaTime;
if (this.IsCorrect())
{
this.correct.SetActive(true);
}
else
{
this.incorrect.SetActive(true);
}
}
}
else if(this.timePassedAfterClick > 0.2f)
{
Destroy(transform.parent.gameObject);
}
}
private bool IsCorrect()
{
int currentNumber = int.Parse(currentText.GetComponent<Text>().text);
if (currentNumber == EquationControler.Result)
{
return true;
}
else
{
return false;
}
}
void OnDestroy()
{
if (GameManager.BrainGamesPlayed == GameManager.MaxBrainGamesPerTunnel)
{
GameManager.ResumeGame();
}
else
{
CanPlay = true;
}
}
}
Note: I make a print line to check if it enters OnCollisionStay and it does indeed but GamesPlayed static variable doesn’t seem to change at all. What can be the problem ?
@deadliness: Uhm where do you actually change "BrainGamesPlayed"?
– Bunny83