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 /
avatar image
0
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
Add comment · 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
1
Best Answer

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

  void OnCollisionEnter

not

  void OnCollsionEnter
Comment
Add comment · 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.

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

Delayed Collisions Bug (includes video demonstration) 1 Answer

Collision, but then only affect ONE of the gameObjects? 2 Answers

2 objects collide, need to destroy one 2 Answers

Have bullets be destroyed when they collide with ANY collider 0 Answers

OnTriggerEnter with exact spot of collision 2 Answers


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