Okay, there is a bug in my game and i tried to narrow it down to the following codes:
The problem is when i change a value to an array A, it seems to also apply the change to another array B.
Can anyone tell me why this would happen please, or any idea what is going wrong, I have been trying so long to figure out whats happening, many thanks.
public class SomeClass : MonoBehaviour {
public GameObject theSave;
private Save saveAccess;
void Start () {
saveAccess= theSave.GetComponent<Save>();
StartCoroutine(SaveGame_waitSec(1f));
}
private IEnumerator SaveGame_waitSec(float sec)
{
yield return new WaitForSeconds(sec);
SaveGame();
}
void SaveGame() {
saveAccess.undo[0, 0] = 0;
saveAccess.curr[0, 0] = 0;
Debug.Log("set undo[0,0] = 20 -- BEFORE: " + saveAccess.undo[0, 0]); //output = 0
saveAccess.undo[0, 0] = 20;
Debug.Log("set undo[0,0] = 20 -- DONE: " + saveAccess.undo[0, 0]); //output = 20
Debug.Log("set curr[0,0] = 99 -- BEFORE: " + saveAccess.curr[0, 0]); //output = 20
saveAccess.curr[0, 0] = 99;
Debug.Log("set undo[0,0] = 99 -- DONE: " + saveAccess.curr[0, 0]); //output = 99
Debug.Log("NOW, PRINT undo[0,0], it should be 20: " + saveAccess.undo[0, 0]); //output = 99
Debug.Log("NOW, PRINT curr[0,0], it should be 99: " + saveAccess.curr[0, 0]); //output = 99
}
}
public class Save: MonoBehaviour {
public int[,] curr = new int[8, 7];
public int[,] undo = new int[8, 7];
}
pls send help T_T