SetActive function not working

Hi there,

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;
        }
    }   
}

Hello

You have no code inside your OnTriggerEnter() to check if the player is inside the trigger.
That’s why your code is not working.

Firstly tag your player gameobject as “Player”.
Then change your method this:
196379-trigger.png

Don’t forget to set the collider to isTrigger inside the inspector so it will properly detect the player.