Game States, communication through scenes and objects

I wanted to have gameplay which changes the state of the next scene which depends on choices made in the scene played before. Is there a way of having runtime states saved, recorded, or sent which I am unaware of.

I mean even having some kind of universal game-state Class which multiple objects can refer to for variable changes... One variable change affect many objects' behaviours.

I am sure I could have asked this question in better computing terms but I hope you can help me guys.

Thanks

1 Answer

1

You could create a new script, place it in your asset folder, use DontDestroyOnLoad and add the static keyword to the declaration of variables, e.g.:

static var Score : int = 0;

function Awake () {
  DontDestroyOnLoad (this);
}

This allows other scripts to reference the value as follows:

NameOfTheScript.Score = ...;

(You do not have to attach this script to a GameObject.)