- Home /
Question by
soccer1mt · Aug 26, 2016 at 04:46 AM ·
uicollidermenu screenworld space
Buttons still "Clickable" after disabling their parent canvas
I am using a laser pointer attached to my vive controller to select buttons off a world space canvas. I did this by attaching a box collider to each button and then using a physics collider. The problem is that when I disable one canvas to go to a different screen, the buttons for canvases that have been deactivated remain active (even though they are not visible on the screen. How do I make sure that the colliders are no longer active after I disable the parent canvas?
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class ItemSelection : MonoBehaviour {
public SteamVR_TrackedObject rightController;
public Canvas MainMenu;
public Canvas MPMenu;
public Canvas OptionsMenu;
public Canvas ExitMenu;
public Canvas TutorialMenu;
void Awake ()
{
MainMenu.enabled = true;
MPMenu.enabled = false;
OptionsMenu.enabled = false;
ExitMenu.enabled = false;
TutorialMenu.enabled = false;
rightController = GetComponent<SteamVR_TrackedObject>();
MainMenu = MainMenu.GetComponent<Canvas>();
MPMenu = MPMenu.GetComponent<Canvas>();
OptionsMenu = OptionsMenu.GetComponent<Canvas>();
ExitMenu = ExitMenu.GetComponent<Canvas>();
TutorialMenu = TutorialMenu.GetComponent<Canvas>();
}
void Update ()
{
if(IsTriggerDown.IsRightDown)
{
Debug.Log("trigTracker is starting");
RaycastHit hit;
Ray shootingRay = new Ray(rightController.transform.position, rightController.transform.forward);
if (Physics.Raycast(shootingRay, out hit, 5f))
{
if (hit.collider.tag == ("SPButton"))
{
SceneManager.LoadScene(1);
IsTriggerDown.IsRightDown = false;
}
else if (hit.collider.tag == ("MPButton"))
{
Debug.Log("You hit the MP Button");
MainMenu.enabled = false;
MPMenu.enabled = true;
IsTriggerDown.IsRightDown = false;
}
else if (hit.collider.tag == ("TutorialButton"))
{
MainMenu.enabled = false;
TutorialMenu.enabled = true;
IsTriggerDown.IsRightDown = false;
Debug.Log("You hit the Tutorial Button");
}
else if (hit.collider.tag == ("OptionsButton"))
{
MainMenu.enabled = false;
OptionsMenu.enabled = true;
IsTriggerDown.IsRightDown = false;
Debug.Log("You hit the Options Button");
}
if (hit.collider.tag == ("ExitButton"))
{
MainMenu.enabled = false;
ExitMenu.enabled = true;
IsTriggerDown.IsRightDown = false;
Debug.Log("You hit the Exit Button");
}
if (hit.collider.tag == ("ReturnMenu"))
{
MPMenu.enabled = false;
OptionsMenu.enabled = false;
ExitMenu.enabled = false;
TutorialMenu.enabled = false;
MainMenu.enabled = true;
IsTriggerDown.IsRightDown = false;
Debug.Log("You hit the Return to Menu Button");
}
if (hit.collider.tag == ("YesExButton"))
{
Application.Quit();
Debug.Log("You hit the Exit Button");
}
else
{
Debug.Log("You missed UI Buttons");
}
}
}
}
}
Comment