纳金网
标题:
Unity3D 玩家管理
[打印本页]
作者:
王者再临
时间:
2014-8-30 01:56
标题:
Unity3D 玩家管理
using UnityEngine;
using System.Collections;
/// <summary>
/// 游戏管理员
/// </summary>
public class GameMaster : MonoBehaviour {
/// <summary>
/// 玩家的复活点
/// </summary>
private Vector3 _playerSpwanPointPos;
void Start () {
//初始化玩家的复活点
_playerSpwanPointPos = new Vector3(836f, 0, 790f);
GameObject go = GameObject.Find(GameSetting.PLAYER_SPWAN_POINT);
if (go == null)
{
Debug.LogWarning("没有找到玩家的复活点");
go = new GameObject(GameSetting.PLAYER_SPWAN_POINT);
go.transform.position = _playerSpwanPointPos;
}
//构建玩家游戏对象
GameObject obj = Resources.LoadAssetAtPath("Assets\\Prefabs\\Player\\Sample Hero\\Player-Swordman.prefab", typeof(GameObject)) as GameObject;
obj = Instantiate(obj) as GameObject;
obj.name = "Player";
//构建主相机
GameObject cam=Resources.LoadAssetAtPath("Assets\\Prefabs\\Player\\Camera\\main Camera.prefab", typeof(GameObject)) as GameObject;
cam = Instantiate(cam) as GameObject;
cam.name = "Main Camera";
cam.GetComponent<MouseOrbit>().m_target = obj;
LoadCharacter();
}
#region 加载角色的信息
/// <summary>
/// 加载角色的信息
/// </summary>
public void LoadCharacter()
{
GameObject go = GameObject.Find("GameSetting");
if (go == null)
{
go = Resources.LoadAssetAtPath("Assets\\Prefabs\\Global\\GameSetting.prefab", typeof(GameObject)) as GameObject;
go = Instantiate(go) as GameObject;
go.name = "GameSetting";
}
GameSetting setting = GameObject.Find("GameSetting").GetComponent<GameSetting>();
//加载角色保存的信息
setting.LoadCharacterData();
}
#endregion
}
复制代码
作者:
heise
时间:
2014-8-30 02:16
谢谢分享
作者:
hyui
时间:
2014-8-30 03:16
Great stuff !
欢迎光临 纳金网 (http://old.narkii.com/club/)
Powered by Discuz! X2.5