I am currently using the SpriteSwap transition mode for a button in the Unity 4.6 beta, and was wondering if there is there a way to permanently change the highlighted sprite from the original assigned in the Inspector through code when that button is pressed?
I think that means that you cannot access the variables in the existing SpriteState, but you can just create a new SpiteState that overrides the old one
Here is something I found on another post:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class TestMenu : MonoBehaviour
{
/// <summary>
/// This is the Sprite we're going to swap to.
/// </summary>
/// <remarks>
/// This is set in Unity's Inspector.
/// </remarks>
public Sprite OtherSprite;
/// <summary>
/// The Array of Images.
/// </summary>
Image[] images;
// Use this for initialization
void Start()
{
// Get all components of type Image that are children of this GameObject.
images = gameObject.GetComponentsInChildren<Image>();
// Loop through each image and set it's Sprite to the other Sprite.
foreach (Image image in images)
{
image.sprite = OtherSprite;
}
}
}