Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我如何用光子游戏解决这个问题_C#_Visual Studio_Unity3d_Photon_Playfab - Fatal编程技术网

C# 我如何用光子游戏解决这个问题

C# 我如何用光子游戏解决这个问题,c#,visual-studio,unity3d,photon,playfab,C#,Visual Studio,Unity3d,Photon,Playfab,我已经跟随了这个教程多人fps系列从表达统一,特别是这一集,我需要一些帮助 我一直跟着视频看到23:30,然后所有的东西都坏了。在客户端加入/创建文件室之前,我收到一个错误消息,说不能实例化。国家:加入。我不知道我该怎么办 我检查了所有的代码和所有东西,但什么都没有。你有解决办法吗?我不知道哪个代码有问题,所以我复制了这段视频之后我编辑的所有三个代码 MpManager脚本: using System.Collections; using System.Collections.Gener

我已经跟随了这个教程多人fps系列从表达统一,特别是这一集,我需要一些帮助

我一直跟着视频看到23:30,然后所有的东西都坏了。在客户端加入/创建文件室之前,我收到一个错误消息,说不能实例化。国家:加入。我不知道我该怎么办

我检查了所有的代码和所有东西,但什么都没有。你有解决办法吗?我不知道哪个代码有问题,所以我复制了这段视频之后我编辑的所有三个代码

MpManager脚本:

    using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine.SceneManagement;

public class MPManager : MonoBehaviourPunCallbacks
{

    public GameObject[] EnableObjectsOnConnect;
    public GameObject[] DisableObjectsOnConnect;

    // Start is called before the first frame update
    void Start()
    {
        PhotonNetwork.ConnectUsingSettings();
        //PhotonNetwork.ConnectToRegion("eu");
    }


    public override void OnConnectedToMaster()
    {
        foreach(GameObject obj in EnableObjectsOnConnect)
        {
            obj.SetActive(true);
        }
        foreach(GameObject obj in DisableObjectsOnConnect)
        {
            obj.SetActive(false);
        }
        Debug.Log("Connected to photon");
    }

    public void JoinFFA()
    {
        PhotonNetwork.AutomaticallySyncScene = true;
        PhotonNetwork.JoinRandomRoom();
    }

    public override void OnJoinRandomFailed(short returnCode, string message)
    {
        CreateFFA();
    }

    public void CreateFFA()
    {
        PhotonNetwork.AutomaticallySyncScene = true;

        RoomOptions ro = new RoomOptions { MaxPlayers = 10, IsOpen = true, IsVisible = true };
        PhotonNetwork.CreateRoom("defaultFFA", ro, TypedLobby.Default);

        SceneManager.LoadScene("FFA");
    }
}
动作脚本:

    using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon;
using Photon.Pun;

public class Movement : MonoBehaviourPun
{
    public KeyCode Left;
    public KeyCode Right;
    public KeyCode Forward;
    public KeyCode Backward;

    [SerializeField]
    private float MoveSpeed = 50;

    private Rigidbody body;
    private GameObject cam;

    // Start is called before the first frame update
    void Start()
    {
        body = GetComponent<Rigidbody>();
        cam = gameObject.transform.GetChild(0).gameObject;
        if (photonView.IsMine)
        {
            cam.SetActive(true);
        }
    }

    // Update is called once per frame
    void Update()
    {
        if (photonView.IsMine)
        {
            float x = Input.GetAxis("Mouse X");
            float y = Input.GetAxis("Mouse Y");

            if (Input.GetKey(Left))
            {
                body.AddRelativeForce(Vector3.left * MoveSpeed, ForceMode.Impulse);
            }

            if (Input.GetKey(Right))
            {
                body.AddRelativeForce(Vector3.left * -MoveSpeed, ForceMode.Impulse);
            }

            if (Input.GetKey(Forward))
            {
                body.AddRelativeForce(Vector3.forward * MoveSpeed, ForceMode.Impulse);
            }

            if (Input.GetKey(Backward))
            {
                body.AddRelativeForce(Vector3.forward * -MoveSpeed, ForceMode.Impulse);
            }
            gameObject.transform.Rotate(new Vector3(0, x, 0));
            cam.transform.Rotate(new Vector3(-y, 0, 0));
        }
    }
}

抱歉,如果我的英语有拼写错误,我的英语不好。

找到了解决方案!我只是将生成时间改为1秒,而不是0,因此玩家在实例化之前有时间加入聊天室。

问题中不能使用不必要的外部链接,请只发布引发错误的代码,而不是所有脚本请提供问题的详细信息。您的确切问题是什么?你是怎么解决的?到底是什么东西没有按预期工作?请不要链接到一个帖子,但复制完整的问题在这里。。。如果由于某种原因,外部链接中断了您的帖子,那么这里的帖子将变得无用,帖子将被编辑!
    using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon;
using Photon.Pun;

public class FFA : MonoBehaviourPun, IPunObservable
{

    public float SpawnTime;
    float timer;
    bool HasPlayerSpawned = false;

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        timer += Time.deltaTime;
        if(timer >= SpawnTime)
        {
            if (!HasPlayerSpawned)
            {
                PhotonNetwork.Instantiate("Player", Vector3.zero, Quaternion.identity, 0);
                HasPlayerSpawned = true;
            }

            timer = 0;
        }
    }

    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if(stream.IsWriting)
        {

        }else if (stream.IsReading)
        {

        }
    }
}