Good evening,
I have some UI buttons, but as my game is for Android, I’m having some problems with changing the state of the button, I have one sprite for the button and one for it when pressed. The problem is, I can’t change the state of the button. Bellow is the script I’m using the check if the button was touched, and I’m sending a message to it. How do I change the state of this button so it can show the right sprite (Pressed)?
void Update () {
if (Input.touchCount > 0 && Input.GetTouch (0).phase == TouchPhase.Began) {
RaycastHit2D buttonHit;
buttonHit = Physics2D.Raycast(this.transform.position, Input.touches[0].position);
if (buttonHit)
{
objectHit = buttonHit.transform.gameObject;
if (objectHit.name == "Button_Play")
{
objectHit.SendMessage("LoadScene",1,SendMessageOptions.DontRequireReceiver);
}
}
}
}