I want to store my data when current running scene was unloaded. For this purpose I have written following code:
void OnDisable ()
{
BackUpPuzzleData();
}
public void BackUpPuzzleData ()
{
if (DataStorage.RetrievePuzzleStatus (difficultyLevel, puzzleId) == Constants.PUZZLE_NOT_OPENED
&& DataStorage.RetrievePuzzleStatus (difficultyLevel, puzzleId) != Constants.PUZZLE_COMPLETED)
DataStorage.StorePuzzleStatus (difficultyLevel, puzzleId, Constants.PUZZLE_RUNNING);
if (DataStorage.RetrievePuzzleStatus (difficultyLevel, puzzleId) == Constants.PUZZLE_RUNNING)
StorePuzzleData ();
}
private void StorePuzzleData ()
{
DataStorage.StorePuzzleTimePassed (difficultyLevel, puzzleId, GameController.gamePlayTime);
foreach (Transform cell in gridTransform) {
CellInformation cellInfo = cell.GetComponent<CellInformation> ();
if (cellInfo != null) {
CellStorage.StorePuzzleCellNumber (difficultyLevel, puzzleId, cellInfo.RowIndex, cellInfo.ColIndex, cellInfo.number);
CellStorage.StorePuzzleCellColor (difficultyLevel, puzzleId, cellInfo.RowIndex, cellInfo.ColIndex, cellInfo.CellColor);
CellStorage.StorePuzzleCellDisplayColor (difficultyLevel, puzzleId, cellInfo.RowIndex, cellInfo.ColIndex, cellInfo.CellDisplayColor);
}
}
}
But when OnDisable method gets called at that time Console giving me following error:
I have already set execution order of scrip in project settings then why I am getting this kind of error?
EDIT: Basically I want to save current game play data so when game player return back he can again start from which he left game.