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 Pathojen · Aug 02, 2020 at 09:20 AM · rigidbodycollidertriggerontriggerenter

OnTriggerEnter not being called, have trigger, RB, and colliders set?

alt textHi!

I have a GameObject that is supposed to set a boolean on its animator to true once a trigger is called. Thing is, I debugged it with print() and found that it was never called? Both the objects have 3D colliders, and one of them has a rigidbody. I have the object that needs to be collided with set to trigger. I triple-checked that my trigger Gameobject's tag is spelled correctly as well. I am lost on what I could be missing. Please help? Thanks.

alt text

Here is the code for the trigger.

     void OnTriggerEnter(Collider other)
     {
 
         if(other.gameObject.tag == ("PlayerAttack"))
         {
         health = health - 40;
         print(health.ToString());
         if(health > 0)
             {
             Anim.Play("GhostLightHit");
             Anim.Play("GhostIdle");
             }
         else if(other.gameObject.tag == ("EnemyTarget"))// The script part that isn't working
             {
             print("Collided");
             Anim.SetBool(Attacking, true);
             Anim.SetBool(canMove, false);
             Audio.clip = otherClip[Random.Range(0,otherClip.Length)];
             
             }
         else
             {
             Instantiate(GhostDead, transform.position, transform.rotation);
             Destroy(gameObject);
             }
         }
     }


targetinspector.png (90.9 kB)
screenshot-25.png (99.1 kB)
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 xxmariofer · Aug 02, 2020 at 10:17 AM 0
Share

we cant tell you you will need to provide us with screenshots or something

avatar image Pathojen · Aug 02, 2020 at 10:38 AM 0
Share

Caught one bug and changed code so the other... EnemyTarget")) is now after the else statement, as I can't have 2 tags. Still does not work, however.

avatar image Pathojen Pathojen · Aug 02, 2020 at 10:41 AM 0
Share

Sorry about that. I just updated the question with pictures.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Pathojen · Aug 02, 2020 at 11:03 AM

I didn't exactly figure it out, but I found a workaround. I added a private boolean canMove, and made it so that it switches to false OnTriggerEnter. Everything in the section for the part that doesn't work has been placed in an if statement to test if the new bool is true or not. If not, then the part that was ignored previously takes place.

Still curious on what I did wrong in the original code, though. There has to be a more effective way of doing things.

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

223 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 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 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 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 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 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 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 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

OnTriggerEnter/Exit called unexpectedly 2 Answers

Access other collider without use of Trigger collider. 1 Answer

Can't get trigger to work 1 Answer

OnTriggerEnter fails to activate 1 Answer

Rigidbody + Multiple Trigger Colliders - OnTriggerEnter - Get which Collider triggered the event issue 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