I have a Scrollbar which use to scroll some Text vertically, i know there is funktion which calls when its used, but how do i make invisibel whent not used and visibel again when used?
public class Test : MonoBehaviour , IPointerDownHandler, IPointerUpHandler
{
public Image image;
void Start()
{
Color col = image.color;
col.a = 0f;
image.color = col;
foreach(Transform t in transform)
{
t.gameObject.SetActive(false);
}
}
public void OnPointerDown (PointerEventData eventData)
{
Color col = image.color;
col.a = 1f;
image.color = col;
foreach(Transform t in transform)
{
t.gameObject.SetActive(true);
}
}
public void OnPointerUp (PointerEventData eventData)
{
Color col = image.color;
col.a = 0f;
image.color = col;
foreach(Transform t in transform)
{
t.gameObject.SetActive(false);
}
}
}
Got it working with this :
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class show : MonoBehaviour {
// Update is called once per frame
void Update () {
gameObject.GetComponent<RectTransform>().localScale = new Vector3(0,0,0);
}
public void ShowScrollBar(){
gameObject.GetComponent<RectTransform>().localScale = new Vector3(1,1,1);
}
}
ShowScrollBar() is the function to assign from the inspector to the OnValueChange event of your scrollBar, put the script on your scrollBar.
It is a bit sensitive though, maybe it can still be improved.