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
1
Question by pepefirst · Apr 18, 2011 at 06:12 PM · collisionontriggerenteroncollisionenter

OnTriggerEnter do not triggers

I wrote this simple script to an i-pad game in which my Player should pick-up automatically apples (when Player and apple enter in touch) from the floor and add points to the score for that. I attached it as a this separate script to my Player and checked the Trigger marks, both in the apple and the Player. Although the easy this seems, the apple do not disappears; that is, I missed something I can't find. Any help, please.

var points : int = 0
function OnTriggerEnter(collisionInfo : Collider){
if(collisionInfo.gameObject.tag == "apple"){    
points++;
audio.PlayOneShot(appleCollect);
Destroy(collisionInfo.gameObject);  
}

}

@script RequireComponent(AudioSource)

Comment
Add comment · Show 4
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 Toxic Blob · Apr 18, 2011 at 06:30 PM 0
Share

As you have an if statement, can you confirm that the tag check is working? Does appleCollect.points increase as you touch the apples?

avatar image Toxic Blob · Apr 18, 2011 at 06:30 PM 3
Share

Also, on the iPad you want to avoid using Destroy as that causes garbage collection and memory reallocation. It's better to simply disable the apple, then re-enable it when needed elsewhere.

avatar image pepefirst · Apr 18, 2011 at 06:50 PM 0
Share

Sorry Toxic Blob, I made an edit to my post after your answers because I got a Unity error message with Collision Points; I changed it by var points. I have not implemented yet the Scorer script but I suppose it will not work either because I do not get the pick-up sound.

avatar image Toxic Blob · Apr 18, 2011 at 07:10 PM 0
Share

Try below points++ adding "Debug.Log("collision with an apple");. If you don't get that then either the tag comparison is failing, or you need a rigidbody as Bampf suggests below

1 Reply

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

Answer by Bampf · Apr 18, 2011 at 06:58 PM

Probably you need to add a rigidbody to one or both of the objects. From the documentation for Box Collider:

Be aware that in order for two Triggers to send out trigger events when they collide, one of them must include a Rigidbody as well. For a Trigger to collide with a normal Collider, one of them must have a Rigidbody attached. For a detailed chart of different types of collisions, see the collision action matrix in the Advanced section below.

The same is true for the other collider types.

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 pepefirst · Apr 18, 2011 at 07:23 PM 0
Share

That was the problem: I forgot to add a rigidbody to the apples prefab. Thanks a lot! Also thanks to Toxic Blob!

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

No one has followed this question yet.

Related Questions

On Trigger Enter, Collide with object, specific collision 1 Answer

Keep doing something while colliding 1 Answer

Response speed in OnCollisionEnter / OnTriggerEnter 1 Answer

Transform collider not detecting collision on rigidbody collider 2 Answers

OnCollisionEnter not working? 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