Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[script] Triggering GUI OnTriggerEnter - Having problems

Discussion in 'UGUI & TextMesh Pro' started by Alex_lemes, Nov 5, 2015.

  1. Alex_lemes

    Alex_lemes

    Joined:
    Nov 14, 2014
    Posts:
    8
    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:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections;
    4.  
    5. public class triggerGUI : MonoBehaviour {
    6.  
    7.     public Canvas retryMenu;
    8.  
    9.  
    10.     void update()
    11.  
    12.     {
    13.  
    14.         retryMenu = retryMenu.GetComponent<Canvas>();
    15.         retryMenu.enabled = false;
    16.  
    17.  
    18.     }
    19.  
    20.     void OnTriggerEnter(Collider other)
    21.     {
    22.         retryMenu.enabled = true;
    23.  
    24.     }
    25.  
    26.  
    27. }
    Any ideas on what's wrong ?
     
  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,683
    You don't use ".enabled" you need to call SetActive(bool) :D
    Hope that helps
     
  3. Alex_lemes

    Alex_lemes

    Joined:
    Nov 14, 2014
    Posts:
    8
    I'm kinda new to scripting and i cannot figure this one out :p

    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 ??
     
  4. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,683
    Code (CSharp):
    1.  
    2.     void OnTriggerEnter(Collider other)
    3.     {
    4.         retryMenu.SetActive(true);
    5.     }
    (From memory, so check it compiles first :D)

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