using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ButtonScript : MonoBehaviour
{
//实现点击鼠标,切换图片
//(物体)
public GameObject NextButton;
//下一张按钮对象
public GameObject LastButton;
//上一张按钮对象
public GameObject ImageTu;
//图片对象
//(组件)
Image imageSprite;//定义图片组件
Button next;//下一张图片组件
Button last;//上一张图片组件
public Sprite [] sprites;//定义精灵组件
int index = 0; //当前下标
//为各个组件赋值(属性)
void Start(){
imageSprite = ImageTu.GetComponent<Image> ();
next = NextButton.GetComponent<Button> ();
last = LastButton.GetComponent<Button> ();
//随机显示一张图片可用
index = Random.Range(0,sprites.Length);
imageSprite.sprite = sprites [index];
}
//切换下一张(方法)
public void NextSprite(){
imageSprite.sprite = sprites [++index];
}
//切换上一张(方法)
public void LastSprite(){
imageSprite.sprite = sprites[--index];
}
//更换按钮状态
void Update(){
if (index == sprites.Length - 1) {
next.interactable = false;
}
else if (index == 0) {
last.interactable = false;
} else {
next.interactable = true;
last.interactable = true;
}
}
}