I have a script error

public class Collision : MonoBehaviour

{

void OnCollisionEnter(Collision collision)

{

   switch(collision.gameObject.tag)

   {

       case ("Friendly"):

       Debug.Log("Run");

       break;

       case "Finish":

       Debug.Log("Win");

       break;

       default:

       Debug.Log("Lost");

       break;

   }

}

}

To me, nothing obvious stands out as an error.

Are you missing
‘using UnityEngine;’

I’m not good at programming but is there a reason for the : instead of the ; in the code?

There is. It’s part of the inheritance for Monobehaviour. It’s also part of the case statement syntax.

no unityengine is there, i dont understand why I am facing the error

that’s a case type bro, colon is must

i am new to coding, can you explain me more ? thnq

Actually, I think I figured it out. I didn’t even consider the name of the class.

Your script cannot be called Collision. It’s already a class that exists in Unity. Call it something else that doesn’t already exist.

1 Like

yes thnq, your’re right

Privacy & Terms