I have a GUI texture that I want to call a function in a script. The other script animates the GUI texture and changes scene / does some other stuff.
Here’s an example of the sort of code I’m using:
//script that animates a GUI Texture gameobject and controls the active screen "titleScreen.js"
var btnSettings : GameObject;
var settingsScreen : GameObject;
var titleScreen : GameObject;
function OnEnable(){
//stuff
}
function exitTitleScreen(){
/stuff
}
function SwitchToSettingsScreen(){
exitTitileScreen();
titleScreen.SetActiveRecursively(false);
settingsScreen.SetActiveRecursively(true);
}
I’d like to make it so that the GUI Texture is able to run the function SwitchToSettingsScreen(), I tried to make a new script, place it on the gameobject in my hierarchy:
//Button script on GUI Texture "button.js"
function OnMouseUp(){
titleScreen.SwitchToSettingsScreen();
}
Unfortunately I get the following error:
An instance of type ‘titleScreen’ is required to access non static member ‘SwitchToSettingsScreen’.
Ideally, I’d like the extra script I’m making for the button to just be in the titleScreen.js and not have to make something like button.js everytime I want to use a button to control a script.
Well, I’m stumped. I’ve also asked this over at unity Questions, to no avail unfortunately. What would be the best way to access the functions in titleScreen.js from a GUI Texture gameobject click / tap?