New GUI system, question

Hello,

I just started using the GUI system and have a couple of questions.
Earlier I would have done this to create a button:

if (GUI.Button (new Rect (352, 400, 224, 83), characterIcon [characterSelectedOne], "")) {
					characterSelectedOne = 0;
				}

This created a dynamic texture swap that I like to use.
I want to use this kind of dynamic texture change in the new unity GUI system.
So I created a button called “TeamSpot1” and On Click() it runs a function called
“TeamSpot1”

using UnityEngine;
using System.Collections;

public class ButtonFunctions : MonoBehaviour {

	public Texture2D[] characterIcon;
	
	public void TeamSpot1 (){

	
		GameObject _controller = GameObject.Find ("Controller");
		Controller controller = _controller.GetComponent<Controller> ();
	
		controller.characterSelectedOne = 0;
	}
}

I don’t know if this is a good way to do this, but I would love to have it work in this system.

Suggetions? Ideas. I looked up resource folder etc, but didn’t manage to make it work.

Well, first thing to note is that the new UI system uses Sprite instead of Texture2D.

Next, if you go to your Button Component there is a drop-down menu called “Transition”, with the option “Sprite Swap”. Depending on what you want to do (and how that works I’ve never used it), that may be enough. If not, you could do

 using UnityEngine;
 //you need this for the UI component classes
 using UnityEngine.UI;

 public class ButtonFunctions(){

//reference to button
public Button button;
public Sprite[] buttonSprites;


public void SomeFunction(){
 button.image.sprite = buttonSprites[0];

}

}