Jump to content

I have a project in Unity where I try to detect if a ball with the tag "Ball" hits the goal with the tag "Goal". But I can't get it to work. Here's my code: 

using UnityEngine;

public class BallController : MonoBehaviour
{
    public Rigidbody Ball;
    public Collider colider;

    void onCollisionEnter (Collision col)
    {   
        if (col.gameObject.tag == "ball" && colider.tag == "Goal")
        {
            Debug.Log("Goal Hit!");
        }
    }
}

It's written in C#

Link to comment
https://linustechtips.com/topic/777444-unity-goal-detection/
Share on other sites

Link to post
Share on other sites

13 minutes ago, TobiZY said:

I have a project in Unity where I try to detect if a ball with the tag "Ball" hits the goal with the tag "Goal". But I can't get it to work. Here's my code: 


using UnityEngine;

public class BallController : MonoBehaviour
{
    public Rigidbody Ball;
    public Collider colider;

    void onCollisionEnter (Collision col)
    {   
        if (col.gameObject.tag == "ball" && colider.tag == "Goal")
        {
            Debug.Log("Goal Hit!");
        }
    }
}

It's written in C#

Change your collier to a trigger in the inspectorbabd use the function ontriggerenter

Link to comment
https://linustechtips.com/topic/777444-unity-goal-detection/#findComment-9805737
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×