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);
    }
}
相关推荐
孟无岐8 小时前
【Laya】Component 使用说明
typescript·游戏引擎·游戏程序·laya
weixin_409383128 小时前
cocos shader三角流光
游戏引擎·cocos2d
Mars-xq10 小时前
godot 毛玻璃效果着色器shader
游戏引擎·godot·着色器
绀目澄清11 小时前
unity3d AI Navigation 中文文档
游戏·unity
绀目澄清13 小时前
Unity 的AI Navigation 系统详细总结
人工智能·unity·游戏引擎
绀目澄清15 小时前
Unity3D AI Navigation 详解:从基础概念到实战应用
unity·游戏引擎
weixin_4093831215 小时前
cocos shader流光文字 不显示透明部分
游戏引擎·cocos2d
绀目澄清15 小时前
Unity3D AI导航系统完全指南:从核心概念到动画耦合
人工智能·unity
__water16 小时前
RHK《模型贴图自由更换位置》
unity·贴图·模型贴图·移动不丢失
JIes__16 小时前
Unity(二)——3D数学
unity·游戏引擎