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 inf3ctedsystem · Feb 23, 2014 at 03:41 AM · not-working

2D Colliders not working

So I have the code to where the player is supposed to walking into the trigger of this object and it's supposed to bring up some gui text you can click on and answer, but Unity is not registering that the player is even colliding with the 2DBoxCollider. I need help because I'm at a stand still in my project and for the life of me I cannot figure this out, I have googled it and nothing works.

 using UnityEngine;
 using System.Collections;
 
 public class ProtatoTalk : MonoBehaviour {
     public string [] answerButton;
     public string [] Questions; 
     bool DisplayDialog = false; 
     bool HasTalkedTo = false;  
 
     void onGUI()
     {
         if (DisplayDialog && !HasTalkedTo)
         {
         GUILayout.BeginArea (new Rect (1, 1, 400, 400)); 
          
     
 
             GUILayout.Label(Questions[0]);
             if(GUILayout.Button (answerButton[0]))
             {
                 GUILayout.Label (Questions[1]);
                 HasTalkedTo = true; 
             }
 
             if(GUILayout.Button (answerButton[1]))
             {
                 GUILayout.Label (Questions[2]);
                 HasTalkedTo = true;
             }
 
     }
         GUILayout.Label (Questions[3]); 
         GUILayout.EndArea(); 
     }
     
     void OnTriggerStay2D()
     {
         Debug.Log ("Player is in Trigger"); 
         if(Input.GetMouseButtonDown(0))
             DisplayDialog = true; 
     }
 
     
         void OnTriggerExit2D()
     {
         DisplayDialog = false;
     }
 }
 
Comment
Add comment · Show 3
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 Invertex · Feb 23, 2014 at 04:01 AM 0
Share

Your OnTrigger functions aren't complete, it should be:

 void OnTriggerStay2D(Collider2D colObj)
 void OnTriggerExit2D(Collider2D colObj)

Right now it's not looking for anything to enter the trigger.

Also, as the documentation says, a trigger will not trigger if neither object has a Rigidbody2D.

avatar image Eric5h5 Invertex · Feb 23, 2014 at 04:07 AM 1
Share

There's no need to include the Collider2D variable if you're not going to use it. This isn't the problem; just void OnTriggerStay2D() etc. is fine for this code.

avatar image Invertex · Feb 23, 2014 at 04:34 AM 0
Share

Ah weird, the documentation made it sound like it was needed. Good to know.

1 Reply

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

Answer by Eric5h5 · Feb 23, 2014 at 04:05 AM

There is no built-in function called "onGUI", so that function won't run unless you specifically call it. Note how in the code you posted, it didn't get syntax highlighted. This is why it's important that you be consistent about capitalizing all function names (and while you're at it, make all your variables start with lower case; don't mix cases like that).

Comment
Add comment · 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

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

21 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 avatar image avatar image avatar image

Related Questions

normal maps aren't showing up in the webplayer 1 Answer

GUI Box not showing! 1 Answer

Multiple Trigger Script doenst works! 1 Answer

GUISkin breakages 2 Answers

Using GUI.BeginGroup inside GUILayout.BeginScrollView doesn't trigger the scrollbar. Why? 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