Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Oct 22, 2013 at 03:00 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by knuckles209cp · Oct 21, 2013 at 08:34 AM · guicollidertrigger

Press button if you are inside a trigger (Sorry)

FIRST of all im sorry for all the things i've said recently i was just getting a little worked up because java is very frustrating since i have just got into it . thank you for the help i'm getting , any help will be appreciated.

SO my question is , how come this says ou can only call GUI functions from inside OnGUI?

 var Switch : GameObject;
 Switch = gameObject.FindWithTag("switch");
 
 
 function OnTriggerEnter (other : Collider) {
 
   if(other.tag == "Player"){
      
     OnGUI ();   
   }
 }
 
 
 function OnGUI (){
 
   if(GUI.Button(Rect(100,100,100,100),"Click to play")){
       Switch.animation.Play("Bridge");
   
 
 }
 
 
 }


And also the Gui button appears even when im not inside the trigger . Feel free to edit my question if it will help me.

Comment
Add comment · Show 1
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 vexe · Oct 21, 2013 at 08:39 AM 0
Share

You shouldn't call OnGUI yourself, it's called automatically. (see) - Your error means.

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by meat5000 · Oct 21, 2013 at 08:41 AM

 if(other.tag == "Player")
 {
     OnGUI();
 }

You have this function call to OnGUI() in a trigger. OnGUI() will get called several times per frame just from including the function.

Instead, enable/disable the element, perhaps by toggling a boolean declared with the rest of your variables.

Comment
Add comment · Show 1 · 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 knuckles209cp · Oct 22, 2013 at 04:58 AM 0
Share

Thank you .

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Trigger GUI working wrong 1 Answer

Restricting a key press to when youre in a trigger? 2 Answers

Can't click gameobject when over another trigger? 1 Answer

Handling mouse events in objects inside a trigger? 0 Answers

Is there a script that will trigger a gui texture when an object is destroyed? 2 Answers


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