I have a problem with making game over canvas visibility on and off.

Hello, I am making game over menu. I have canvas and i put some text in it and when I play the canvas dissapear but when I hit collider nothing happens, I was trying to Debug text on collider but dosen’t work.
I am stuck.

Code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class gameover : MonoBehaviour {
    public Canvas cav;
    public bool x;
    public Collider coli;

    private void Start()
    {
        cav = GetComponent<Canvas>();
        x = false;
        cav.gameObject.SetActive(false);
        coli = GetComponent<Collider>();
    }

    void OnCollisionEnter(Collision coli)
    {
        if (coli.gameObject.tag == "toto")
        {
            Debug.Log("lolz");
            x = true;
        }
    }
    private void Update()
    {
        if (x == true)
        {
            cav.gameObject.SetActive(true);
        }
        if (x == false)
        {
            cav.gameObject.SetActive(false);
        }
    }
}

Good day.

Are you sure the methid is beeing called? Did you put any Debug.Log as a first command of the method to see if it is beeing called?

If not, the problem os not in the code, is in the scene. Read carefully the manual to be sure when this method is called, be sure that your objects have all that need (colliders not marked as trigger, rigibodies, etc…)

Is a 3D collision, or 2D? there is another method for 2D

Be sure the tag is toto, and not Toto or things like this.
Test & feedback

good luck

Bye!