How to make a collision trigger a change in the value of a variable?

What I want to do is make it so when a my player collides with anything the value of a variable will change. How do I do that?

Use the code provided by @andrew-lukasik if yout collider is not marked as trigger. If you need to use a trigger, you must use the OnTriggerEnter family functions.

Also make sure to have a rigidbody in the same object as the collider.

I recommend you to check for documentation, Unity - Scripting API: Collider and read it, don’t worry if do not understand everything, just read it and will discover things for sure.

Good luck! :grinning:

public int counter = 0;

void OnCollisionEnter(Collision collision)
{
    counter = counter + 1;

    // shorter forms of the same:
    // counter += 1;
    // counter++;
}