- 最后登录
- 2021-7-6
- 注册时间
- 2012-12-27
- 阅读权限
- 90
- 积分
- 76145
 
- 纳金币
- 53488
- 精华
- 316
|
- public class Script : MonoBehaviour {
- public GameObject[] characterPrefabs; //人物的预设体
- private GameObject[] characterGameObjects; //把人物装进一个数组里
- private int selectedIndex = 0; //当前选择的人物是第几个
- private int length; //所有可供选择的角色个数
- // Use this for initialization
- void Start () {
- length = characterPrefabs.Length;
- characterGameObjects = new GameObject[length];
- for (int i = 0; i < length; i++)
- {
- characterGameObjects[i] = GameObject.Instantiate(characterPrefabs[i], transform.position, Quaternion.identity) as GameObject;
- }
- UpdateCharacterShow();
- }
-
- // Update is called once per frame
- void Update () {
-
- }
- void UpdateCharacterShow() //更新所有角色的显示
- {
- characterGameObjects[selectedIndex].SetActive(true);
- for (int i = 0; i < length; i++)
- {
- if (i!=selectedIndex)
- {
- characterGameObjects[i].SetActive(false); //把未选择的角色设置为隐藏
- }
- }
- }
- public void OnNextButtonClick() //当我们点击了下一个按钮
- {
- selectedIndex++;
- selectedIndex %= length;
- UpdateCharacterShow();
- }
- public void OnPrevButtonClick()//当我们点击上一个按钮
- {
- selectedIndex--;
- if (selectedIndex==-1)
- {
- selectedIndex = length - 1;
- }
- UpdateCharacterShow();
- }
- }
复制代码 |
|