Well, i´m looking for a way to save performance for my game…
i have this code:
function Update () {
if (Input.touches.Length > 0){
for (var r : int = 0; r < Input.touchCount; r++){
if (this.guiTexture.HitTest(Input.GetTouch(r).position)){
if (Input.GetTouch(r).phase == TouchPhase.Began) Debug.Log("A");
else if (Input.GetTouch(r).phase == TouchPhase.Ended) Debug.Log("B");
}
}
}
}
i put it on each guiTexture used to be a touch button…
i just was curious if i have 4 touches button, then this script will be instanced 4 times, if it contents Update function, i can imagine that this will not be a good idea to get a better performance.
What do you think if i just use a general script aiming to each touchButton ?
for instance:
private var touchBtn : GUITexture[];
function Awake () {
touchBtn = new GUITexture[4];
for (var g : int = 0; g <= 3; g++) touchBtn[g] = GameObject.Find("GUI/button" + g.ToString());
}
function Update () {
if (Input.touches.Length > 0){
for (var r : int = 0; r < Input.touchCount; r++){
//If button 0 is touched
if (touchBtn[0].HitTest(Input.GetTouch(r).position)){
if (Input.GetTouch(r).phase == TouchPhase.Began) //Do things for Button 0
}
else if (touchBtn[1].HitTest(Input.GetTouch(r).position)){
if (Input.GetTouch(r).phase == TouchPhase.Began) //Do things for Button 1
}
//... and so... until finish button [3]
}
}
}
This script will be instanced just one time on a root gameObject…
will this help me to gain performance?..
Thanks.