using DG.Tweening; using System; using System.Collections; using System.Collections.Generic; using System.Reflection; using UnityEngine; using UnityEngine.UI; public class LookImg : MonoBehaviour { public Sprite[] sprites; int curImgIndex = 0; public Transform imgtip; public Button up; public Button down; bool initEnd=false; void Start() { up.onClick.AddListener(() => { if (curImgIndex <= 0) { curImgIndex = sprites.Length - 1; } else { curImgIndex--; } ChangeTip(curImgIndex); }); down.onClick.AddListener(() => { if (curImgIndex >= sprites.Length - 1) { curImgIndex = 0; } else { curImgIndex++; } ChangeTip(curImgIndex); }); } void Update() { if (!initEnd) return; GetComponent().sprite = sprites[curImgIndex]; imgtip.GetChild(curImgIndex).gameObject.SetActive(true); } void ChangeTip(int index) { for (int i=0;i().localScale = new Vector2(width, height); } for (int i = 0; i < imgtip.childCount; i++) { imgtip.GetChild(i).gameObject.SetActive(false); } initEnd = true; } }