- Home /
Gui button for attachment
So what i want to do is be able to press a gui button on my screen ( which will say ACOG ) , and when i click it the acog renderer will be enabled , and the iron sights will be turned off , but when i click the acog button instead of 2 buttons it will say iron sights where the button acog was. heres the code :
var attachmentOne : GameObject;
var attachmentTwo : GameObject;
function Update ()
{
if ( Input.GetButton("Disable1"))
{
attachmentOne.renderer.enabled = false;
}
if ( Input.GetButton("Disable2"))
{
attachmentTwo.renderer.enabled = false;
}
}
Answer by robertbu · Aug 04, 2013 at 06:38 AM
I suggest you spend a bit of time studying the GUI system since you are asking about GUI but your script does not use GUI. Here is one link with some basic examples. As for your question:
var attachmentOne : GameObject;
var attachmentTwo : GameObject;
private var strings : String[] = ["ACOG", "iron sights"];
private var i = 0;
function OnGUI() {
if (GUI.Button(Rect(50,50, 100, 50), strings[i])) {
i = (i + 1) % 2;
attachmentOne.renderer.enabled = (i == 0);
attachmentTwo.renderer.enabled = (i == 1);
}
}
Your answer

Follow this Question
Related Questions
A node in a childnode? 1 Answer
DragWindowPosition Doesn't Work 1 Answer
I am having an issue with returning an array 2 Answers
Unity GUI Button Options 0 Answers
GUI.PasswordField getting erased after clicking on the PasswordField. 0 Answers