一个小知识点,怕忘记,所以记录下。废话不多说,直接上代码:
未赋值之前:
使用下面代码赋值:
using UnityEngine;
using UnityEngine.UI; public class Test : MonoBehaviour
{
public Button button;
public Sprite normalSprite; //正常图片
public Sprite highlightedSprite; //高亮图片
public Sprite pressedSprite; //点击图片
public Sprite disabledSprite; //禁用图片
private void Start()
{
button.GetComponent<Image>().sprite = normalSprite;
//将按钮变化模式改为 SpriteSwap
button.transition = Selectable.Transition.SpriteSwap;
//设置变化状态
SpriteState state = new SpriteState();
state.highlightedSprite = highlightedSprite;
state.pressedSprite = pressedSprite;
state.disabledSprite = disabledSprite;
button.spriteState = state;
}
}
赋值后:
就是这么简单,相信大家应该学会了吧!