码迷,mamicode.com
首页 > 其他好文 > 详细

CharacterCreation

时间:2016-06-25 09:34:25      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

using UnityEngine;
using System.Collections;

public class CharacterCreation : MonoBehaviour {

public GameObject[] characterPrefabs;
public UIInput nameInput;//用来得到输入的文本
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, transform.rotation) as GameObject;
}
UpdateCharacterShow();
}

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();
}
public void OnOkButtonClick() {
PlayerPrefs.SetInt("SelectedCharacterIndex", selectedIndex);//存储选择的角色
PlayerPrefs.SetString("name", nameInput.value);//存储输入的名字
//加载下一个场景
Application.LoadLevel(2);
}

}

CharacterCreation

标签:

原文地址:http://www.cnblogs.com/ZeroMurder/p/5615812.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!