I can not for the life of me create a simple button image swap when pressed in the new UI.
Basically I have two images. Picture a running man icon, and walking man icon. All I want is the Walking man icon to display when the app loads, then when the Walking man is clicked, it turns into a Running man icon. Then when the Running man icon is displayed and clicked, it turns back to the Walking man icon. Other functions will be added later.
A simple image swap of the “Image (Script) - Source Image” inside my “Button” gameObject.
But nothing I’m creating inside of C# or the Unity Editor is working. This is how I’ve started my code but not sure how to finish it and make it work with the new buttons:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class Buttons : MonoBehaviour {
public Sprite runningMan;
// Use this for initialization
void Start () {
runningMan = Resources.Load("Run.png", typeof(Sprite)) as Sprite;
GetComponent<SpriteRenderer>().sprite = runningMan;
}
How do I finish this to work with my Button??