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.