C# Collision and tag question.

Hello I’m trying to learn C# and at the moment I am trying to make a script that will print to the console if my player walks into a cube, I am going to attach this script to the cube. Here is my script at the moment,

void Update ()

void OnTriggerEnter (Collision collider)

{if (collider.gameObject.tag == “Player”)
print(“Collision”);}
}

It’s not working and I’m not sure why, could someone explain where I’ve made a mistake please? :slight_smile:

You’ve combined two different collision-related functions. There’s OnCollisionEnter(Collision collision) and OnTriggerEnter(Collider collider), but you’re trying to receive a Collision in the latter of the two. Also, you need to ensure that the collider on your cube has the “Is Trigger” box checked if you want to use OnTriggerEnter.

Do you plan on walking through the box, or just bumping into the trigger Zone?

Thank you Ruub that fixed it, and I planned to walk through the box. :slight_smile: