- Home /
How to make a Panel (Or Scrollbar) Appear on Button Click
Hey! So In my building placement im starting to get lots of buildings so I want a scrollbar to popup when I press the Build button. Im having lots of trouble with this as I have a GuiScript (Referenced Below) and Im not sure how to add it.
GUIscript:
using UnityEngine;
using UnityEngine.UI;
public class GUIScript : MonoBehaviour {
BuildManager bm;
Button house, tower, path, field;
bool buildopen = false;
// Use this for initialization
void Start () {
bm = GameObject.Find("BuildManager").GetComponent<BuildManager>();
Canvas cv = GameObject.Find("Canvas").GetComponent<Canvas>();
house = cv.transform.FindChild("HouseButton").gameObject.GetComponent<Button>();
tower = cv.transform.FindChild("TowerButton").gameObject.GetComponent<Button>();
path = cv.transform.FindChild("PathButton").gameObject.GetComponent<Button>();
field = cv.transform.FindChild("FieldButton").gameObject.GetComponent<Button>();
}
public void ActiveteBuilding(Button pressedBtn)
{
if (pressedBtn.name == "BuildButton")
{
if (buildopen)
{
//bm.DeactivateBuildingmode();
house.gameObject.SetActive(false);
tower.gameObject.SetActive(false);
path.gameObject.SetActive(false);
field.gameObject.SetActive(false);
pressedBtn.image.color = Color.white;
buildopen = false;
}
else
{
//bm.ActivateBuildingmode();
house.gameObject.SetActive(true);
tower.gameObject.SetActive(true);
path.gameObject.SetActive(true);
field.gameObject.SetActive(true);
pressedBtn.image.color = new Color(255, 0, 255);
buildopen = true;
}
}
else
{
switch (pressedBtn.name)
{
case "HouseButton":
bm.SelectBuilding(0);
break;
case "TowerButton":
bm.SelectBuilding(1);
break;
case "PathButton":
bm.SelectBuilding(2);
break;
case "FieldButton":
bm.SelectBuilding(3);
break;
}
pressedBtn.image.color = new Color(155, 120, 255);
bm.ActivateBuildingmode();
}
}
void Update()
{
if (buildopen)
{
if (!bm.isBuildingEnabled)
{
if (house.image.color != Color.white)
house.image.color = Color.white;
if (tower.image.color != Color.white)
tower.image.color = Color.white;
if (path.image.color != Color.white)
path.image.color = Color.white;
if (field.image.color != Color.white)
field.image.color = Color.white;
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
How do you access the Blocking Mask of GraphicsRaycaster in code? 2 Answers
Animation not playing on game object activated by script 3 Answers
Canvas, Scroll Rect, Panels, Panes? 0 Answers
[c#] first script isnt disabling canvas and player cant move (issue with first script) 0 Answers
How do I get the width and height of text then apply it to a UI panel? 0 Answers