• 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
Question by ShadowNukePie · Dec 18, 2016 at 07:46 AM · collisionontriggerenteroncollisionenter

OnCollisionEnter not working?

I know this question is asked a lot, and I've had this problem before ,but nothing I can find solves my problem. I have a simple script, so that when an object (tree) is hit with an axe, it will drop a piece of wood. However, It doesn't ever even count as getting hit. The axe is attached to the FPS Controller, and i'm wondering if that's where my issue stems from. I've also tried OnTriggerEnter, doesn't work. I've had the tree with a rigidbody, every piece with a rigid body, the axe and every component with a rigid body, "is trigger" on and off, but nothing works. What should I do? Here's my script:

 // Use this for initialization
 void Start () {
 Debug.Log("test");
 }
 
 // Update is called once per frame
 void Update () {
     if(woodcounter >= 15)
         {
         Instantiate(wood, new Vector3(a, 0.5f, a), Quaternion.identity);
         a++;
         woodcounter = 0;
         
     }
 }
 public GameObject wood;
 public float a;
 public float woodcounter;
 void OnCollsionEnter(Collision other)
 {
     Debug.Log("1");
     if(other.gameObject.tag == "axe")
     {
         Debug.Log("2");
         woodcounter++;
     }
 }

}

Thanks for the help! This script is attached to the tree, in case that matters. Both the axe and tree are under an empty game object that holds all the child parts, but I don't think that should matter. And yes, i've tried changing the script so that it is on all parts the tree.

Thanks! :)

Comment

People who like this

0 Show 1
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 getyour411 · Dec 18, 2016 at 07:56 PM 0
Share

@ShadowNukePie I'm just guessing here but don't spend too much time working on this functionality thinking you will transfer it to Terrain trees because that won't work; search for solutions here on UA if you are planning that.

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by tanoshimi · Dec 18, 2016 at 07:47 AM

  void OnCollisionEnter

not

  void OnCollsionEnter
Comment
Creeper_Math

People who like this

1 Show 3 · 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 ShadowNukePie · Dec 18, 2016 at 02:23 PM 0
Share

Thanks! It works :D Can't believe i missed something that simple! I wish that would create an error. :/

avatar image tanoshimi ShadowNukePie · Dec 18, 2016 at 05:05 PM 0
Share

There's no reason for it to create an error, because it's not wrong. You can name custom functions (nearly) however you want. But if you want them to get called by Unity, you need to name them exactly the same as Unity's callback system expects.

avatar image ProtoTerminator · Dec 18, 2016 at 03:58 PM 0
Share

^ This. Thankfully Visual Studio with Unity Tools now has the On... functions with intellisense.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to detect collision without OnCollisionEnter or OnTriggerEnter? 1 Answer

simple onCollision and onTrigger problem 1 Answer

OnTriggerEnter do not triggers 1 Answer

Colliding two GameObjects 1 Answer

On Trigger Enter, Collide with object, specific collision 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