hey guys, im trying to make some simple gui texture buttons that when clicked, zooms in and out the camera. one button is zoom in, another is zoom out.
now im trying to reference the button in a script which is attached to the camera already.
ive tried some methods like void onmousedown however im not sure how to reference gui textures outside the script?
any help would be great
Assuming you have two texture variables (textureZoomIn and textureZoomOut) in your script attached to camera, then you need to do:
void OnGUI()
{
if (GUI.Button(new Rect(0, 0, 100f, 30f), textureZoomIn))
{
ZoomIn();
}
if (GUI.Button(new Rect(0, 32f, 100f, 30f), textureZoomOut))
{
ZoomOut();
}
}
UPDATE: when writing above snippet, I was thinking of more common way of using textures in GUI buttons. For your case different solution is required:
void Update()
{
if (Input.GetMouseButtonDown(0))
{
if (ZoomIN.HitTest(Input.mousePosition))
{
ZoomIn();
}
if (ZoomOUT.HitTest(Input.mousePosition))
{
ZoomOut();
}
}
}