- Home /
.setactive not working? on new unity ui 4.6
The ui stays on the screen even after this code: this invokes a hideGUI() method
if (currentPlayerIndex < amountPlayers - 1) {
players[currentPlayerIndex].hideGUI();
currentPlayerIndex++;
players[currentPlayerIndex].showGUI();
} else {
players[currentPlayerIndex].hideGUI();
currentPlayerIndex = 0;
players[currentPlayerIndex].showGUI();
}
this is the thing from a monobehaviour class:
public virtual void hideGUI(){
panelendturnButton.SetActive (false);
}
this is from the script on the game object that derives from the above class:
public override void hideGUI(){
base.hideGUI ();
Debug.Log("user hide");
}
the debug.log in the override goes off, but the gui still stays on the screen :S
Info about the hierarchy:
I have a canvas, with attached to it a panel. This panel has a button attached to it. Trying to make the panel referenced in the inspector as panelendturnButton didn't work, so i made a prefab of the canvas which allowed me to make the prefab panel as a GameObject reference for the script.
So basically I have a canvas and it's prefab is referenced in the inspector, maybe this is the problem? but trying to reference the panel directly from the hierarchy didn't work :S
also tried instantiating the canvas from the prefab, made no difference
What is you GUI hierarchy, and what is panelendturnButton exactly?
Are you sure you are not just deactivating the button object and not the graphical representation?
Answer by Mmmpies · Feb 11, 2015 at 11:30 AM
Working on a guess that panelendturnButton is a UI Button can you try
panelendturnButton.gameObject.SetActive(false);
You need tp reference the gameObject to set active.
tried this didn't work
edited the post on info of the hierarchy
Is that a ui Button? And are you trying to hide the entire ui or just the panelendturnButton?
It is indeed a UI button, but i'm trying to hide the panel which only has the button attached to it, might be worth reading the edited part of the post
your update hadn't appeared. Just how Answers works, it may have been in $$anonymous$$oderation or just slow appearing. You might also want to consider not being so short with people who are helping you for free, the vast majority on here are not employees of Unity, just trying to help others out.
Also if someone gives you a correct answer, tick it, I note you've asked 3 questions and none have been ticked, yeah I know this isn't answered yet but get a reputation for not ticking and some people won't help you.
So what you want is something like this:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
// then, in your class, create a public Canvas
public Canvas myCanvas;
public void HideCanvas()
{
myCanvas.gameObject.SetActive(false);
}
public void ShowCanvas()
{
myCanvas.gameObject.SetActive(true);
}
Drag the script onto the canvas and then highligh the canvas. Drag the canvas onto the empty slot in the script attached to the canvase.
Highlight the button click + in the onClick section. Drag the Canvas with the script onto it and from the dropdown select myScriptName -> HideCanvas.
Typed blind into the editor so watch for typos.
Thanks a lot, adding a script to the Canvas itself made it so I could add the reference from the hierarchy itself
Your answer
Follow this Question
Related Questions
A NullReferenceException even though I'm sure that object was assigned? 1 Answer
Converting UI RectTransform to Screen Pixel and vice-versa 5 Answers
Move gameobject to button in new 4.6? 0 Answers
Unity 4.6 Beta Controller Menu Button Movement 0 Answers
Unity 4.6 - Rotating with Mouse Issue 0 Answers