Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by toby · Aug 03, 2011 at 08:05 AM · disableonguienabledcs0246

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.

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Aldwoni_legacy · Aug 03, 2011 at 08:11 AM 0
Share

is this all your code?

avatar image toby · Aug 03, 2011 at 08:15 AM 0
Share

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

avatar image Meltdown · Aug 03, 2011 at 08:15 AM 0
Share

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?

avatar image toby · Aug 03, 2011 at 08:59 AM 0
Share

yes exactly what u say

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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?

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image toby · Aug 03, 2011 at 09:06 AM 0
Share

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

avatar image Bunny83 · Aug 03, 2011 at 09:23 AM 0
Share

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.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Disabling THIS script from code 1 Answer

How to make an open and close box?,How to make open and close a box? 0 Answers

Enabling/Disabling Multiple Tagged objects 1 Answer

Information about Behaviour.enabled 1 Answer

Disable function OnGUI after 4 seconds 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges