0

我正在关注用户: quill18creates on youtube 多人 FPS 教程。

https://www.youtube.com/watch?v=CnKc9k6shQA

将离线模式设置为 true 时出现问题。当我尝试运行我的应用程序时,我得到了

Debug.Log("No spawn spots!!!");

控制台日志上的消息。但是,当切换回在线模式时,我可以找到生成点并正常播放吗?我在下面附上了我的代码(也可以在 youtube 视频上看到)。

using UnityEngine;
using System.Collections;

public class NetworkManager : MonoBehaviour {

public Camera standbyCamera;
private SpawnSpot[] spawnSpots;

public bool offlineMode = false;

// Use this for initialization
void Start () {
    Connect ();
    spawnSpots = GameObject.FindObjectsOfType<SpawnSpot> ();
}

// Update is called once per frame
void Update () {

}

void Connect() {
    if (offlineMode) {
        PhotonNetwork.offlineMode = true;
        OnJoinedLobby();
    } else {
        PhotonNetwork.ConnectUsingSettings ("0.0.0.1");
    }
}

void OnGUI() {
    GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString ());
}

void OnJoinedLobby() {
    Debug.Log ("OnJoinedLobby");
    PhotonNetwork.JoinRandomRoom ();
}

void OnPhotonRandomJoinFailed() {
    Debug.Log ("OnPhotonRandomJoinFailed");
    PhotonNetwork.CreateRoom (null);
}

void OnJoinedRoom() {
    Debug.Log ("OnJoinedRoom");
    SpawnMyPlayer ();

}

void SpawnMyPlayer() {
    Debug.Log ("SpawnMyPlayer");

    if (spawnSpots == null) {
        Debug.Log("No spawn spots!!!");
        return;
    }

    SpawnSpot mySpawnSpot = spawnSpots [Random.Range (0, spawnSpots.Length)];
    GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate ("Player", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
    myPlayerGO.GetComponent<UnityStandardAssets.Characters.FirstPerson.FirstPersonController>().enabled = true;
    myPlayerGO.GetComponent<AudioSource> ().enabled = true;
    myPlayerGO.transform.FindChild ("FirstPersonCharacter").gameObject.SetActive (true);
    standbyCamera.enabled = false;
}
}
4

1 回答 1

0

我知道我迟到了,但我认为问题出在 Connect 功能上,请将您的 Start 功能更改为:

void Start () {
    spawnPoints = GameObject.FindObjectsOfType<SpawnPoint>();
    Connect();
}
于 2015-12-22T08:33:48.180 回答