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 /
  • Help Room /
This question was closed Sep 12, 2015 at 07:20 PM by Extrapafurdio for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Extrapafurdio · Sep 12, 2015 at 10:40 AM · collider2dtriggersontriggerenter2d

void OnTriggerEnter() not working properly?

 public bool testTrigger = false;


 void onTriggerEnter2D(Collider2D key)
 {
     if (key.gameObject.CompareTag("Key"))
     {
         testTrigger = true;
         key.gameObject.SetActive(false);
     }
 }    

Simple as that, I just want to deactivate the key in the hierarchy. But, when the character enters the trigger, nothing happens. Not even the boolean appears as true in the inspector. This script is attached to the player game object, not to the key I want to deactivate. What is wrong if this code?

Comment
Add comment · Show 2
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 Positive7 · Sep 12, 2015 at 10:44 AM 1
Share

You're checking if the $$anonymous$$ey gameObject enters the trigger. Shouldn't you check if (key.gameObject.CompareTag("Player")) ?

But that would set your Player deactive.

 public bool testTrigger = false;
 public GameObject key;
 void Start(){
 key = GameObject.FindGameObjectWithTag("$$anonymous$$ey");
 }
 
  void onTriggerEnter2D(Collider2D other)
  {
      if (other.gameObject.CompareTag("Player"))
      {
          testTrigger = true;
          key.gameObject.SetActive(false);
      }
  }
avatar image Extrapafurdio Positive7 · Sep 12, 2015 at 07:19 PM 0
Share

I got it! I think I misunderstood how OnTriggerEnter works. Thank you very much! And I forgot the capital "o" when calling the method...

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

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

Related Questions

Calling Input from another script 3 Answers

How to trigger functions like OnTriggerEnter2d and OnTriggerExit2d with raycasthit2d ? 1 Answer

Unity 2D: Glitchy Collision/Triggers Problem 0 Answers

BoxCollider2D OnTriggerEnter2D 1 Answer

reset destroyed collider after game restart 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