I wrote details on what I’m trying to do with notes in the script:
//This is the script from Unity's FPS tutorial.
function Start () {
SelectWeapon(0);
}
function Update () {
//Works fine with the touch input, but I want my GUITexture do that job
if (Input.touchCount > 0 &&
Input.GetTouch(0).phase == TouchPhase.Began)
//I don't need weapon switching
if (Input.GetKeyDown("1")) {
SelectWeapon(0);
}
else if (Input.GetKeyDown("2")) {
SelectWeapon(1);
}
}
function SelectWeapon (index : int) {
for (var i=0;i<transform.childCount;i++) {
// Activate the selected weapon
if (i == index)
transform.GetChild(i).gameObject.SetActiveRecursively(true);
// Deactivate all other weapons
else
transform.GetChild(i).gameObject.SetActiveRecursively(false);
}
}
I’d highly appreciate a reply. I hope you understand my question.
All you need to do is create a new script and add that script to your GUITexture object. Then add an OnMouseDown( ) method to the script and do whatever you want to do inside that.
Or if you want to implement your own hit test, you can compare the current mouse position on a click with a GUIElement using GUIElement.GetScreenRect().