Author Topic: Show/hide NGUI Panel OnTriggerEnter/OnTriggerExit  (Read 6406 times)

GantZ_Yaka

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 21
    • View Profile
Show/hide NGUI Panel OnTriggerEnter/OnTriggerExit
« on: May 07, 2013, 10:20:57 PM »
Why this code doesnt work?
  1. using UnityEngine;
  2. using System.Collections;
  3. public class AreaScript : MonoBehaviour {
  4. public GameObject uiObject;            
  5. void Start () {
  6. uiObject = GameObject.Find("PanelTrigger1");   
  7. NGUITools.SetActive(uiObject,false);
  8.         }
  9.     void OnTriggerEnter(Collider other)
  10.     {
  11.         NGUITools.SetActive(uiObject,true);
  12.         }
  13.         void OnTriggerExit(Collider other)
  14.     {
  15.         NGUITools.SetActive(uiObject,false);
  16.     }  
  17. }
  18.  

Why its hard to find NGUI-tutorial of such an important thing as hiding/showing panels during entering the trigger?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Show/hide NGUI Panel OnTriggerEnter/OnTriggerExit
« Reply #1 on: May 08, 2013, 02:13:56 AM »
Because you can't destroy objects from within a physics callback such as OnTrigger. Set a variable instead such s "hasbeenDestroyed = true", and check for it in the Update function.

hazzius

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Show/hide NGUI Panel OnTriggerEnter/OnTriggerExit
« Reply #2 on: April 26, 2014, 06:12:55 PM »
What i must to do for enable HUD objects then i pass EnablerTriggerZone and disable HUD objects then i pass DisablerTriggerZone ?

Attach not working EnablerTriggerZone script. All Debug is fine, i see it all in console in time.
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class s_BlueTrigger : MonoBehaviour {
  5.         private GameObject Blue;
  6.         public bool BlueTrigger = false;
  7.  
  8.         void Start ()
  9.         {
  10.                 Blue = GameObject.FindGameObjectWithTag("4_Blue");
  11.                 Debug.Log("Blue Detected");
  12.         }
  13.  
  14.         void Update ()
  15.         {
  16.                 if (BlueTrigger)
  17.                 {
  18.                         NGUITools.SetActive (Blue, true);
  19.                         Debug.Log("Blue True");
  20.                 }
  21.         }
  22.  
  23.         void OnTriggerEnter (Collider Other)
  24.         {              
  25.                 if (Other.gameObject.tag == "Player")
  26.                 {
  27.                         BlueTrigger = true;
  28.                         Debug.Log("Blue Triggered");
  29.                 }
  30.         }
  31. }              


Why this not work? I newbie in C# Unity and NGUI. Plz make some big answer.
And tell me, why i cant use grid in realtime? It put objects in grid and sort them only at start. If i turn off and on components at Play Mode, the components not automatically sorted in grid, just activated in places there been disabled?

Sry for bad English.
« Last Edit: April 26, 2014, 06:26:34 PM by hazzius »

Sahkan

  • Jr. Member
  • **
  • Thank You
  • -Given: 9
  • -Receive: 0
  • Posts: 74
    • View Profile
Re: Show/hide NGUI Panel OnTriggerEnter/OnTriggerExit
« Reply #3 on: April 27, 2014, 11:20:41 AM »
Why don't you use Renderer.enabled = true/fales on this object ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Show/hide NGUI Panel OnTriggerEnter/OnTriggerExit
« Reply #4 on: April 27, 2014, 11:55:15 PM »
I already explained why this is not possible, hazzius:
Because you can't destroy objects from within a physics callback such as OnTrigger. Set a variable instead such s "hasbeenDestroyed = true", and check for it in the Update function.
This is just how Unity works. You cannot destroy things inside a physics callback. OnTrigger is a physics callback.