Please Help!

I am getting an error.


And this is my code:
using UnityEngine;

public class Collision : MonoBehaviour

{

private void OnCollisionEnter(Collision other)

{

    switch(other.gameObject.tag)

    {

        case "Friendly":

            Debug.Log("Friendly");

            break;

        case "Finish":

            Debug.Log("Finish");

            break;

        case "Fuel":

            Debug.Log("Fuel");

            break;

        default:

            Debug.Log("Harmful");

            break;

    }

}

}
Can you tell me which part of my code is wrong?

Welcome to the community! Take some time to have a look around. :slight_smile:

You’ve called your script “Collision”, but Collision is already a class in Unity. In this case, you’re trying to use Unity’s Collision class in the Collision other parameter, but Unity is confused about which “Collision” you mean.

The simplest fix is to rename your script to something else and this should be fine. :slight_smile:

public class MyCollision : MonoBehaviour  //Rename your script 
{
   void OnCollisionEnter(Collision other) 
   {
      //Your code here
   }
}
1 Like

Thank you for your solution. I didn’t know that. :slightly_smiling_face:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms