What’s up Unitarians,
I have a small GUITexture acting as a button. Quite simply, it pauses and unpauses the game upon click. The script is put on the GUITexture, which is included into the scene automatically - so its not generated via code.
The problem is that, since the script is on the actual GUITexture, I cannot change the texture of the button programmatically - as to say - whenever I click on it. I want it so that when I click on the button, it does it stuff, and it changes the image of the button.
There are questions similar to this, but in those cases, the script is not actually on the GUITexture, when in this case, it is mandatory that it is.
I’ll show you the code as it is:
#pragma strict
public var PauseGUI : GUITexture;
private var paused : boolean = false;
public var Pause_False : Texture2D;
public var Pause_True : Texture2D;
/*function Start () {
}*/
function Update () {
for (var touch : Touch in Input.touches) {
if (touch.phase == TouchPhase.Began) {
// Construct a ray from the current touch coordinates
var ray = Camera.main.ScreenPointToRay (touch.position);
if (Physics.Raycast (ray)) { //What happens when touched
if (paused == false) { //Pause the game
paused = true;
Time.timeScale = 0;
PauseGUI.enabled = true;
this.texture = Pause_True; //This is where it makes no sense
}
if (paused == true) { //Unpause the game
paused = false;
Time.timeScale = 1;
PauseGUI.enabled = false;
this.texture = Pause_False; //This is where it makes no sense
}
}
}
}
}
FYI, PauseGUI is NOT the button itself, it is a completely separate GUITexture that is enabled when the game is “paused”