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 post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Vulkrey · Feb 27, 2014 at 07:32 AM · collidervariablesscore

Collider not functioning correctly

When I use the :

     void onTriggerEnter(Collider collider){
     if (collider.gameObject.CompareTag("Enemy")){
         Player.score += 1;
     }

code the Player.score isn't being increased by one.

Also when:

 void OnTriggerEnter(Collider collider){
     if (collider.gameObject.CompareTag("Projectile")){
         DestroyObject(this.gameObject);
     if (collider.gameObject.CompareTag("Player")){
         Destroy(this.gameObject);
     }
 }

Is processed the object isn't being destroyed when the colliders' tag is "Player" How to fix

I am using C#. Both the enemy and the projectile are moving.

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 robertbu · Feb 27, 2014 at 07:35 AM 0
Share

One of the object has to have a non-kinematic Rigidbody, and both have to have colliders. If you put a this:

 Debug.Log(collider.tag+", "+collider.name);

...just inside the OnTriggerEnter(), does if fire?

avatar image JaneY · Feb 27, 2014 at 08:29 AM 1
Share

Try collider.gameObject.tag == "Enemy" ins$$anonymous$$d of "compareTag".

1 Reply

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

Answer by MrYOLO · Feb 27, 2014 at 09:35 AM

Try to put the rigidbody on the moving object, then it will trigger the OnTriggerEnter function when it collide with an collider. I'm not clear of your struction(which has the rigidbody and which is moving, also the script is bundled for which gameobject). But the OnTrigerEnter is only called when one of the gameObject has rigidbody and the moving one is the one with rigidbody. It's seems if the one with rigidbody is not the moving one, it will sleep at the processing, I think it a way unity use to optimize the Engine. Good Luck.

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

23 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

Related Questions

GUI text not updateing 1 Answer

Scoring system based on time remaining and targets hit 4 Answers

Score not adding up? 1 Answer

how can i keep the variable show in play mode 0 Answers

How do I stop adding to a variable? 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