我知道这是一个很长的问题很安静,但我几天都在不停地尝试,我仍然没有找到任何帮助...... 我想用一个统一服务器设置一个小的在线PVP游戏,并产生玩家从现在起一切正常。现在出现了2个未解决的问题...我无法更改播放器克隆创建的生成点,也不能让相机跟随你的角色...... 我希望有人可以帮助我:))
继承了网络脚本:
using UnityEngine;
using System.Collections;
public class NetworkManager : MonoBehaviour
{
private const string typeName = "Elemental Fox";
private const string gameName = "Elemental Fox";
private bool isRefreshingHostList = false;
private HostData[] hostList;
public GameObject playerPrefab;
void OnGUI()
{
if (!Network.isClient && !Network.isServer)
{
if (GUI.Button(new Rect(100, 100, 250, 100), "Start Server"))
StartServer();
if (GUI.Button(new Rect(100, 250, 250, 100), "Refresh Hosts"))
RefreshHostList();
if (hostList != null)
{
for (int i = 0; i < hostList.Length; i++)
{
if (GUI.Button(new Rect(400, 100 + (110 * i)300, 100), hostList[i].gameName))
JoinServer(hostList[i]);
}
}
}
}
private void StartServer()
{
Network.InitializeServer(16, 25000, !Network.HavePublicAddress());
MasterServer.RegisterHost(typeName, gameName);
}
void OnServerInitialized()
{
Debug.Log("initialized!");
SpawnPlayer();
}
void Update()
{
if (isRefreshingHostList && MasterServer.PollHostList().Length > 0)
{
isRefreshingHostList = false;
hostList = MasterServer.PollHostList();
}
}
private void RefreshHostList()
{
if (!isRefreshingHostList)
{
isRefreshingHostList = true;
MasterServer.RequestHostList(typeName);
}
}
private void JoinServer(HostData hostData)
{
Network.Connect(hostData);
}
void OnConnectedToServer()
{
Debug.Log("Connected!");
SpawnPlayer();
}
void changePosition()
{
GameObject player = GameObject.Find("Player(Clone)");
player.transform.position = new Vector3(3, 12, 3);
}
private void SpawnPlayer()
{
Network.Instantiate(playerPrefab, Vector3.up * 10, Quaternion.identity, 0);
}
}