I have buttons that aren’t using the GUI system, but instead are just textures on gameobjects. I’m using raycast.hit to detect whether the button is hit. I want the button to swap textures while a touch is on it to give the visual effect of being pressed down. I haven’t been able to get the picture to switch back to it’s original when the touchphase ends.
function Update(){
if (fingerCount>0||Input.GetMouseButtonDown(0)) {
var raybutton: Ray;
if ((fingerCount>0)&&(Input.GetTouch(0).fingerId==0)&&(Input.GetTouch(0).phase==TouchPhase.Began)){
raybutton= OrthoCam.ScreenPointToRay(Vector3(Input.GetTouch(0).position.x,Input.GetTouch(0).position.y));
}
var hitbutton: RaycastHit;
if (Physics.Raycast(raybutton, hitbutton)) {
var buttonName=hitbutton.transform.gameObject.name;
if (buttonName=="Restart"){
GameObject.Find("Restart").renderer.material.mainTexture=Resources.Load("RestartPressed");
var restartflag=true;
}
}
for (var touch = 0; touch < Input.touchCount; ++touch) {
if (Input.GetTouch(touch).phase == TouchPhase.Ended||Input.GetTouch(touch).phase == TouchPhase.Canceled) {
if(restartflag==true){
GameObject.Find("Restart").renderer.material.mainTexture=Resources.Load("Restart");
restartflag=false;
}
}
}
}