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 bladelock · Apr 14, 2012 at 12:48 PM · collisioncollision detectiononcollisionenter

OnCollisionEnter not working with Platform and Ball game

Hello, I have a Ball which moves based on user input with a rigidbody and a collider, and I have a platform named "Start", which is where the ball is first placed. Start has a collider, but no rigidbody

I have a script attached to the Start platform named Start.cs, which is supposed to say something in the log if anything collides with it.

Here is the code for Start.cs using UnityEngine; using System.Collections;

public class Start : MonoBehaviour {

 // Update is called once per frame
 void Update () {        
 
 }
 
 public void onCollisionEnter(Collision collision)
 {
     Debug.Log("The battle has begun");
 }
     

}

Apparently, nothing shows up in the Log with my code. However, I have another code attached to the Ball named Movement.cs which has a Working OnCollisionEnter function, which can actually leave something in the log if it collides with something.

Below is the part of the code of Movement.cs, particularly the portion with OnCollisionEnter()

using UnityEngine; using System.Collections;

public class Movement : MonoBehaviour {

 bool canjump = true;
 int noofcollisions = 0;
 
 
 
 void OnCollisionEnter(Collision collision)
     {
         canjump = true;
         
         Debug.Log("Collided with " + collision.gameObject.name + " " + noofcollisions + " times");
         noofcollisions++;
     
         if(collision.gameObject.name == "Finish")
     {
         Debug.Log("Congratulations!!! You have won the game!!!");
     }
     
         //calculate distance of jump
         
         //Debug.Log(GameObject.Find("Ball").transform.position.x);
     
     }
 

}

What causes the OnCollisionEnter function of my Start platform to not work? How can I fix this problem? Cheers.

Comment
Add comment
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

1 Reply

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

Answer by kolban · Apr 14, 2012 at 01:10 PM

When writing Unity JavaScript or C# scripts, it is very important to check spelling and case of methods calls. A function called Foo() is not the same as a function called foo().

Looking at your original code, you have coded:

 public void onCollisionEnter(Collision collision)

where what I believe you mean to code was

 public void OnCollisionEnter(Collision collision)

Note the first character of the function name.

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 bladelock · Apr 15, 2012 at 04:11 AM 0
Share

Amazing!!! I missed the capitalized "O". That solved the problem. Now something appears in the log. It works.

Thank you!

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

Smooth movement for the block upon player collision,Smooth box movement 0 Answers

Help with collisions and destroy please 1 Answer

Collisions with Grabbable Items 0 Answers

Collision detection when no collision happens,OnCollision is called without a collision 1 Answer

Why does my AI miss me every few feet? 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