- Home /
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
Answer by efge · Mar 20, 2011 at 01:23 PM
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.)
Your answer
Follow this Question
Related Questions
How to save a Scene during a game? 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Unity 3d(Space) Questions 1 Answer
Scene changing 1 Answer
AI enemy scripting help 1 Answer