The code Im using is working fine, but I have to assign the script to every GUItexture I want to use as a button. I’m overhauling my entire menu system, so I want to simplify everything by just attaching this script once to an empty gameobject, then on hittest, look for tag, then run if statements to direct the flow from there. Such as
if(****.tag == "Chapter1"){
*Go to chapter 1 level select*
}
if(*****.tag == "Chapter 2"){ etc...
But I don’t know how to detect tag on hittest. If it’s even possible. Here is the code Im using now.
#pragma strict
var startButton : GUITexture;
public var deleteSave : boolean = false;
public var Chapter : int;
function Start () {
startButton.color.a = 0.0f;
yield WaitForSeconds(2);
yield Fade(0.0, 1.0, 2.0); // fade up
// yield Fade(1.0, 0.0, 2.0); // fade down
}
function Update ()
{
AutoResize(Screen.width, Screen.height);
if(deleteSave==true){
PlayerPrefs.DeleteAll();
deleteSave=false;
}
for (var i = 0; i < Input.touchCount; ++i)
{
if(startButton.HitTest(Input.GetTouch(i).position)){
if (Input.GetTouch(i).phase == TouchPhase.Began)
{
if(Input.GetTouch(i).tapCount == 1)
{
if(Chapter==1){
}
}
}
}
}
}
public static function AutoResize(screenWidth:int, screenHeight:int):void
{
var resizeRatio:Vector2 = Vector2(Screen.width / parseFloat(screenWidth), Screen.height / parseFloat(screenHeight));
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3(resizeRatio.x, resizeRatio.y, 1.0));
}
function Fade (startLevel :float, endLevel :float, duration :float) {
var speed : float = 0.5/duration;
for (var t :float = 0.0; t < 1.0; t += Time.deltaTime*speed) {
startButton.color.a = Mathf.Lerp(startLevel, endLevel, t);
yield;
}
}