[script] Triggering GUI OnTriggerEnter - Having problems

Hello, i’m trying to activate a GUI menu when the player enters a trigger. Its so when the player enters the final platform of the level, a GUI Canvas appears on the screen and allows the player to hit continue in order to go to the next level.

My script doesn’t get any errors, but does not seem to work and i cannot figure out why…

Here is the script:

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

public class triggerGUI : MonoBehaviour {

    public Canvas retryMenu;


    void update()

    {

        retryMenu = retryMenu.GetComponent<Canvas>();
        retryMenu.enabled = false;


    }

    void OnTriggerEnter(Collider other)
    {
        retryMenu.enabled = true;

    }

 
}

Any ideas on what’s wrong ?

You don’t use “.enabled” you need to call SetActive(bool) :smile:
Hope that helps

I’m kinda new to scripting and i cannot figure this one out :stuck_out_tongue:

I’m guessing i would have to apply the Canvas to an object and then apply the script to activate / deactivate the object, which should react with the canvas as it would be a child object ??

    void OnTriggerEnter(Collider other)
    {
        retryMenu.SetActive(true);
    }

(From memory, so check it compiles first :smile:)

You can activate / deactivate any component / GO on the canvas, it’s up to you what pattern fits your goals.