我正在为 Android 2d 应用程序制作一个菜单,我在多个菜单中有一堆 UI 面板,当我按下下一个right或上一个left按钮时,脚本应该设置下一个面板处于活动状态并停用前一个面板,我尝试过这样做这与带有游戏对象的公共类一起使用,但这不起作用,并且认为列表应该起作用。
在 Unity 编辑器中,我将大小设置为 4 并将 4 个面板拖到脚本中,但出现此错误:
ArgumentOutOfRangeException:参数超出范围。参数名称:索引
这是脚本的相关部分:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class MenuControl : MonoBehaviour
{
//Buttons
public GameObject ShipUpgradeRight;
public GameObject ShipUpgradeLeft;
//Ships
private int shipUpgradeSelected = 0;
List<GameObject> ShipList = new List<GameObject>();
public void Keyword (string keyword)
{
if (keyword == "ShipUpgradeLeft") {
shipUpgradeSelected--;
ShipList[shipUpgradeSelected].SetActive (true);
ShipList[shipUpgradeSelected+1].SetActive (false);
}
if (keyword == "ShipUpgradeRight") {
shipUpgradeSelected--;
CheckShip ();
ShipList[shipUpgradeSelected].SetActive (true);
ShipList[shipUpgradeSelected-1].SetActive (false);
}
}
}