Hello,
I'm a complete newbie, attempting to save a bunch of global board information across scenes. In particular, I'm making a board game, and would like to have an object shared across all scenes representing the current state of the board, so that it can be saved, redrawn upon leaving menus, etc.
At the moment, I have the following scripts set up with dummy code, just to see what would happen... but haven't been able to get anything to actually run, even after fiddling. I tried to create a 'minimal' amount of code; I hope it is in fact representative. It certainly doesn't run.
EDIT: Added a minimal code example.
as a script, not attached to anything:
class Unit extends System.Object {
var img:String;
var unitName:String;
function SetImage(img:String) {
this.img=img;
}
function GetImage() {
return this.img;
}
}
In the 'title' scene:
static var BLAH:Unit;
function Awake() {
DontDestroyOnLoad(this);
}
function Start() {
BLAH.SetImage("Hello");
}
function Update () {
}
(attached to a new GameObject that does nothing else)
In the 'load' scene, attached to a GameObject that does nothing else:
function OnGUI () {
if(GUI.Button(Rect(0,560,100,50),
"Level 1")) {
print(GlobalBoardObjects.BLAH.GetImage());
Application.LoadLevel("game");
}
}
I have to agree, post some code. It's really nice that you wrote a quite detailed question but when you say you got some errors and you don't know if it's a syntax problem or a "logical" problem we can't really help you since we don't know what's going wrong. Do you use C#? (I just guessed because you said you derived from MB) You can edit your question at any time to add/change information. Also have a look at the editing help regarding code highlighting and general markup. http://answers.unity3d.com/editing-help
– Bunny83Thanks! I hope the above is representative. I'm writing in Javascript, since that seems to be the language of most tutorials (in 'real life' I write mostly C++ stuff for my own work)
– anon19656182