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);
    }
}
相关推荐
WinstonJQ12 小时前
AirSim无人机仿真入门(一):实现无人机的起飞与降落
python·机器人·游戏引擎·ue4·无人机
Jet_5816 小时前
神庙逃亡(Temple Run)IL2CPP 逆向实战:从 APK 到 Frida 实现角色无敌
unity·il2cpp·逆向工程·frida·android逆向·hook技术·游戏逆向
Dr.勿忘1 天前
MUMU模拟器adb连接失败:cannot connect to 127.0.0.1:16384: 由于目标计算机积极拒绝,无法连接。 (10061)
游戏·unity·adb·游戏程序·调试·模拟器
垂葛酒肝汤2 天前
Unity中的协程的原理
unity·游戏引擎
垂葛酒肝汤2 天前
Unity第一个项目
unity·游戏引擎
Sator12 天前
Unity的InputSystem常见问题和疑惑解答
java·unity·游戏引擎
郝学胜-神的一滴2 天前
QtOpenGL多线程渲染方案深度解析
c++·qt·unity·游戏引擎·godot·图形渲染·unreal engine
IMPYLH2 天前
Lua 的 Table 模块
开发语言·笔记·后端·junit·游戏引擎·lua
Howrun7772 天前
虚幻引擎_控制角色移动的三种方法
游戏引擎·虚幻
速冻鱼Kiel2 天前
GASP笔记01
笔记·ue5·游戏引擎·虚幻