Title says it all. Basically my script is trying to move this window around
var doWindow0 : boolean = true;
var window0x = 100;
var window0y = 100;
var yMoveAmount = 5;
function DoWindow0 (windowID : int) {
if (GUI.Button (Rect (10,30, 80,20), "Click Me!")) {
Debug.Log("Button clicked.");
//This is where I am stuck, I need to move the window by
//a certain amount over time. What I have below does
//not work.
window0y += yMoveAmount * Time.deltaTime;
}
}
function OnGUI () {
if (doWindow0)
GUI.Window (0, Rect (window0x, window0y, 200, 60), DoWindow0, "Basic Window");
}
This isn’t working because window0y is an integer, and yMoveAmount * Time.deltaTime generate only small increments, which are truncated to 0 when added to an integer variable.
When you don’t specify the variable type, Unityscript infers it from the initialization value, which in this case is an int (100); if you change the value to 100.0, the variable will be declared as a float:
var doWindow0 : boolean = true;
var window0x = 100.0; // use a float initialization value...
var window0y: float = 100; // or declare the variable type explicitly
var yMoveAmount = 5;
function DoWindow0 (windowID : int) {
...
But there’s another possible problem: GUI.Button executes only once when pressed, thus the window will do a small jump each time you click the button. If you want it to be shifted while the button is pressed, use GUI.RepeatButton.