- Home /
How to : enable/disable OnGUI() script on C#
void OnGUI () {
if ( GUI.Button ( new Rect ( 3,100, 200, 30 ), "Quit Finding")) {
TeleportLocation code = GetComponent<TeleportLocation>();
code.enabled = false;
ButtonContent scan = GetComponent<ButtonContent>();
scan.enabled = true;
}
The type or namespace name `ButtonContent' could not be found. Are you missing a using directive or an assembly reference?
All of this script were attached in FPS.
sorry, it still have..for the beginning using System.Collections; using UnityEngine;
public class TeleportLocation : $$anonymous$$onoBehaviour
if i deleted:
ButtonContent scan = GetComponent(); scan.enabled = true;
it works~ but i want to appear the ButtonContent
Your question is rather unclear. Are you trying to enable and disable a specific button. So if you click on one button, you want to disable another?
Answer by Bunny83 · Aug 03, 2011 at 08:47 AM
First you don't need to use GetComponent to access the current instance of TeleportLocation. Your class IS a TeleportLocation so by writing
enabled = false;
You will disable this script.
Your actual problem is that it seems you don't have this "ButtonContent" class. Are you sure you have a script that is called ButtonContent? And also make sure it's attached to the same object or GetComponent will fail.
Anyway, the error can't be misinterpreted: the compiler can't find a class that is called ButtonContent.
Can you explain what Buttoncontext should be?
The ButtonContent.js is only a button when pressed it will appear a list of places (TeleportLocation.cs).So, in TeleportLocation.cs i have "Quit Finding" when pressed it will disable TeleportLocation.cs and enable ButtonContent.js. 3 of the script were attached to same object. Pardon, what did u mean by "ButtonContent" class? can i have an example?.... thanks
Your problem is definitely the typical JS / C# mixing problem. In order to use a script from another language it has to be in a compile-group before the script that is accessing it.
http://unity3d.com/support/documentation/ScriptReference/index.Script_compilation_28Advanced29.html
In general you should avoid mixing different languages.