Unity 动态切换图片

cs 复制代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

/// <summary>切换对象显示</summary>
public class SwitchObject : MonoBehaviour
{
    public GameObject[] goList;

    public Button nextButton;
    public Button previousButton;

    private void Awake()
    {
        previousButton.onClick.AddListener(Previous);
        nextButton.onClick.AddListener(Next);
    }

    private int index;

    private void OnEnable()
    {
        index = 0;
        changeObj();
    }

    public void Next()
    {
        index++;
        if (index > goList.Length - 1) index = goList.Length - 1;
        changeObj();
    }

    public void Previous()
    {
        index--;
        if (index < 0) index = 0;
        changeObj();
    }

    private void changeObj()
    {
        for(int i=0;i< goList.Length;i++)
        {
            goList[i].SetActive(i == index);
        }

        previousButton.interactable= (index != 0);
        nextButton.interactable = (index != goList.Length - 1);

        //previousButton.gameObject.SetActive(index != 0);
        //nextButton.gameObject.SetActive(index != goList.Length - 1);
    }
}
相关推荐
天人合一peng3 小时前
unity 生成标记根据背景色变色为明显的颜色
unity·游戏引擎
魔士于安3 小时前
Unity 超市总动员 超市收银台 超市货架 超市购物手推车 超市常见商品
游戏·unity·游戏引擎·贴图·模型
CandyU23 小时前
Unity —— 数据持久化
unity·游戏引擎
zh路西法3 小时前
【Unity实现Oneshot胶卷显形】游戏窗口化与Win32API的使用
游戏·unity·游戏引擎
迪捷软件4 小时前
显控系统虚拟仿真的工程化路径
游戏引擎·cocos2d
凡情8 小时前
android隐私合规检测
android·unity
小贺儿开发8 小时前
Unity3D 本地 Stable Diffusion 文生图效果演示
人工智能·unity·stable diffusion·文生图·ai绘画·本地化
Swift社区9 小时前
传统游戏引擎 vs 鸿蒙 System 架构
架构·游戏引擎·harmonyos
mxwin1 天前
Unity Shader 半透明物体为什么不能写入深度缓冲?
unity·游戏引擎·shader
晚枫歌F1 天前
三层时间轮的实现
网络·unity·游戏引擎