I have different scenes that work fine except when I reach one specific scene. The different thing about this scene is the scripts. A game manager script and a card script. (The game is a personnalized memory game based on the memory card game). Every time I reach that scene, Unity freezes and I can’t play it nor load another scene (using a loadonclick script). I am new to Unity and this is the first real problem I found. Especially when this same scene used to work fine when I first finished it yesterday… Anyway, here is the script I am currently using
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CardScript : MonoBehaviour {
public static bool DO_NOT = false;
[SerializeField]
private int _state;
[SerializeField]
private int _cardValue;
private bool _initialized = false;
private Sprite _cardBack;
private Sprite _cardFace;
private GameObject _manager;
void Start() {
_state = 1;
_manager = GameObject.FindGameObjectWithTag("Manager");
}
public void setUpGraphics() {
_cardBack = _manager.GetComponent<GameManager>().getCardBack();
_cardFace = _manager.GetComponent<GameManager>().getCardFace(_cardValue);
flipCard();
}
public void flipCard() {
if (_state == 0)
_state = 1;
else if (_state == 1)
_state = 0;
if (_state == 0 && !DO_NOT)
GetComponent<Image> ().sprite = _cardBack;
else if (_state == 1 && !DO_NOT)
GetComponent<Image> ().sprite = _cardFace;
}
public int cardValue {
get { return _cardValue; }
set { _cardValue = value; }
}
//50
public int state {
get { return _state; }
set { _state = value; }
}
public bool initialized {
get { return _initialized; }
set { _initialized = value; }
}
public void falseCheck() {
StartCoroutine(pause());
}
IEnumerator pause() {
yield return new WaitForSeconds(1);
if (_state == 0)
GetComponent<Image>().sprite = _cardBack;
else if (_state == 1)
GetComponent<Image>().sprite = _cardFace;
DO_NOT = false;
}
}
The part that I changed a lot lately was the flipcard part because I had some trouble getting it to work, so I’m guessing the problem could be coming from there?