RPG黑暗之光(2)人物选择场景搭建、人物选择UI、人物选择控制
2015-08-23 18:05
549 查看
RPG黑暗之光(2)人物选择场景搭建、人物选择UI、人物选择控制
1、人物选择场景搭建
略。2、人物选择控制
1、创建空物体挂载脚本CharacterCreation.cs。2、将人物制成Prefab。
CharacterCreation.cs
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]) as GameObject; } UpdateCharacterShow(); } // Update is called once per frame void UpdateCharacterShow() { characterGameObjects[selectedIndex].SetActive(true); for (int i = 0; i < length; i++) { if (i != selectedIndex) { characterGameObjects[i].SetActive(false); } } } public void OnNext() { int temp = selectedIndex + 1; selectedIndex = temp % 2; UpdateCharacterShow(); } public void OnPrev() { int temp = selectedIndex + 1; selectedIndex = temp % 2; UpdateCharacterShow(); } public void Ok() { PlayerPrefs.SetInt("SelectedCharacterIndex", selectedIndex); Debug.Log("--->>>"+nameInput.value); PlayerPrefs.SetString("name", nameInput.value); //加载下一个场景 } }
其中。文本输入框主要由以下函数操作:
public void Ok() { PlayerPrefs.SetInt("SelectedCharacterIndex", selectedIndex); Debug.Log("--->>>"+nameInput.value); PlayerPrefs.SetString("name", nameInput.value); //加载下一个场景 }
====================================================================================
结束。
相关文章推荐
- Android基础UI之TextView实现跑马灯效果
- Android UI之TextView实现图文混合效果
- 编译内核 mkimage" command not found - U-Boot images will not be buil
- IOS开发基础UIPickerView循环显示
- RequestAnimationFrame
- [SoapUI] Context is per test case, every test case has a different context
- MapValue排序
- An Intuitive Explanation of Fourier Theory
- elasticsearch的研究与使用(四)Query
- Android UI 绘制过程浅析(一)LayoutInflater简介
- RPG黑暗之光(1)开始场景搭建、开始UI
- hibernate Criteria Query
- poj 3368 Frequent values(段树)
- ueditor 1.4+ 网页文本编辑器安装 jsp
- 黑马程序员--Java基础学习(GUI图形化界面)第二十二天
- iOS UI基础-4.1应用程序管理 字典转Model
- ueditor1-4-3 编辑器使用教程
- Maximum Value(哈希)
- Maximum Value(哈希)
- Asking questions