'Why is SetActive not working in my script?

A new problem has just appeared in my code. In OnTriggerEnter i'm testing if the player collides with the obstacle. When I tell the script to display a message it works fine. But when I replace the Debug.Log("test"), with: deadScreen.gameObject.SetActive(true) to enable my death screen, it just dosen't work and I don't know why. Any help would be appreciated. Thanks in advance.

⠀⠀

Here's my CollisionWithObstacle script that's attached to my obstacle:⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀

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

public class CollisionWithObstacle : MonoBehaviour
{
    public GameObject deadScreen;
    private bool isShown = false;
    public static bool alive = true;
    void Start()
    {
        isShown = false;
    }

    private void OnTriggerEnter(Collider other)
    {
        alive = false;
    }

    private void Update()
    {
        if (!alive)
        {
            deadScreen.SetActive(true);
            deadScreen.active = true;
            isShown = true;
        }
    }   
}


Solution 1:[1]

Most of the time that I encountered this problem is because other scripts are interacting with the gameobject. Furthermore if it's UI you can try to use CanvasGroup and switch alpha between 0-1 and block raycasts. Let me know how it works out for you

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Raining Cycles