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 /
avatar image
0
Question by SpeedTutor · May 14, 2013 at 02:31 PM · errorguitextontriggerexit

Triggerexit, behaviour issue

Hello, I have a problem with disabling a GUIText, in the scene "OnTriggerExit". The code at the very bottom doesn't throw and error until I have exited the collider and shows "Not set to an instance of an object". I'm not really sure how to disable this GUIText.

using UnityEngine; using System.Collections;

 public class MyController : MonoBehaviour 
 
 {
     public GameObject Door;
     bool Mission01 = false;
     public GUIText XPtext;
     
 
     void OnTriggerEnter (Collider Collided)
     {
         if (Collided.gameObject.tag == "MerchantCollider")
         {
             XPtext.text = "Go collect item";
             //GetComponent.<XPtext>().enabled = true;
         }
         
         else if (Collided.gameObject.tag == "Door")
         {
             //Debug.Log ("Door");
             if (Mission01)
             Door.gameObject.animation.Play ("Open");
         }
         
         else if (Collided.gameObject.tag == "Cube")
         {
             Mission01 = true;
             Destroy (Collided.gameObject);
         }    
     }    
     
     void OnTriggerExit (Collider Collided)
     {
         if (Collided.gameObject.tag == "MerchantCollider")
         {
             
             var guiComponent = GetComponent("XPtext").guiText;
             guiComponent.enabled = false;
         }
     }
 }

Thanks!

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 bodec · May 14, 2013 at 02:43 PM 0
Share

I'm not a pro at program$$anonymous$$g but looks to me that you are mixing c# and java in the function.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by darksider2000 · May 14, 2013 at 03:15 PM

 var guiComponent = GetComponent("XPtext").guiText;
 guiComponent.enabled = false;

That. Ok so the way I see it you got this code from another Unity Answers thread, which is perfectly fine, but you should always check to see if the code you're implementing fits in your own code.

In this case the main problem is that you're mixing between Javascript and C# ("var" is used strictly in Javascript). Also I see that the GUIText XPtext has already been defined in your code at line 6, so you don't have to use GetComponent().

This should work just fine:

 void OnTriggerExit (Collider collided)
 {
    if(collided.gameObject.tag == "MerchantCollider") {
       XPtext.enabled = false;
    }
 }

Also, just a small remark I have to mention - try to avoid naming your variables with an uppercase letter in the beginning, this might help avoid problems further down along the road.

Hope this helps :)

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 SpeedTutor · May 14, 2013 at 03:44 PM 0
Share

I thought it was Javascript originally, but I'm sure the thread said it was C#. Fairly poor lapse of judgement on my end.

Thanks for the information! I always assume it's going to be harder than it really is!

As for the uppercase, people have mentioned that to me before but I hate using lowercase. I'm not going to be program$$anonymous$$g for much longer.

Needless to say, cheers!

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

14 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

Related Questions

CAN SOMEONE FINALLY HELP ME! 3 Answers

Erratic movement problem 2 Answers

[CLOSED] 2 errors but i don't know exactly (including picture) 2 Answers

How do I Reset Unity and get a different license? 0 Answers

Character Problems 0 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