im trying to setup a texture to be clickable. Before anyone says it, i know that there are button for this. But I’m using texture.
my code looks like this:
#pragma strict
var background: Texture;
var tweak: Texture;
var level: Texture;
var jam: Texture;
var gear: Texture;
var toTheMax: Texture;
var gearButton: Rect;
var tweakButton: Rect;
function Start ()
{
gearButton = Rect(20,Screen.height/2,Screen.width/6.5,Screen.height/8);
tweakButton = Rect(Screen.width/6.5+40,Screen.height/2,Screen.width/6.5,Screen.height/8);
}
function Update ()
{
if(Input.GetMouseButtonUp)
{
if(gearButton.Contains(Input.mousePosition))
{
Debug.Log("GEAR");
}
if(tweakButton.Contains(Input.mousePosition))
{
Debug.Log("TWEAK");
}
}
}
function FixedUpdate()
{
}
function OnGUI()
{
GUI.DrawTexture(Rect(0,0,Screen.width, Screen.height),background);
GUI.DrawTexture(Rect(20,20,Screen.width/3,Screen.height/3),toTheMax);
GUI.DrawTexture(Rect(20,Screen.height/2,Screen.width/6.5,Screen.height/8),gear);
GUI.DrawTexture(Rect(Screen.width/6.5+40,Screen.height/2,Screen.width/6.5,Screen.height/8),tweak);
}
with this code i have 2 errors that i cant figure out:
1: the Rects that I’m assigning the 2 public Rect variables to in start seems to be above the actual texture and i cant figure out why, because I’m using the exact same dimensions.
2: when im hovering my mouse over those 2 invisible Rects it does the debug.log even when im not touching the mouse button at all. (i also tried it with GetMouseButtonDown and it still runs the line regardless of the mouse button state)