I tried both methods of changing the variable, spinning and typing. But the variable is clinging to 20…why?
Well, without code, it is hard to see what is going on. However, I have a theory:
You made your variable a public variable on an object. That object is stated to have the number from when you first created it, and you are trying to change it in the script. Since that object is already in the scene with the script attached it holds the last value that it saw. Which, is the value it was created with…
You can either change it on the object, or change it in the script and reset the script on the object.
var number=20; // This number can only now be changed on the object...
private var letter = "X"; // this value can only be changed in script.
I fight this occasionally when testing things, i want to go back to the script and nothing in changing… then I remember it is a public variable.
Is it a static var?
@BMB
I do that all the time… for some reason I always forget to use the inspector and instead change my initial public var values in script and forget that it doesn’t update live instances of the script in the scene.
Static or private, both keep the value from script at runtime. The static holds the value in the object but overrides it at run time.
I only asked if it was static thinking maybe he’s trying to change it in multiple instances, a lot of people confuse static with member variables.
My mention of my own blunders, I was referring to public vars as I specified.
I just write var [name of variable] : [type of variable] = value;
I just thought there were variables and private variables. Static variables is self-explanatory, members I have no idea…
Here is the code:
var windowRect0 : Rect;
//var GUIstyle : GUIStyle;
var Text : TextAsset;
function Start (){
transform.parent.GetComponent("MouseLook").enabled = false;
GetComponent("MouseLook").enabled = false;
Screen.showCursor = true;
}
function OnGUI () {
windowRect0 = GUILayout.Window (0, windowRect0, DoMyWindow0, "Getting Started");
}
// Make the contents of the window
function DoMyWindow0 (windowID : int) {
GUI.BringWindowToFront(0);
GUI.Label(Rect(5, 15, 300, 20), "First off, press the left shift key to lock/unlock the");
GUI.Label(Rect(5, 30, 300, 20), "cursor to allow easy navigation of the UI");
// Make the windows be draggable.
GUI.DragWindow (Rect (100,100,10000,10000));
}
windowRect0.width is what is giving me issues…
private var windowRect0 : Rect;
//use it as a private, until you are done testing. ;)
same problem
Well either way it’s not an issue now. I have copied the code from the scripting reference for GUI.Window…all is well now.