PhotonView不存在。

huangapple go评论114阅读模式
英文:

PhotonView Does not Exit

问题

Received RPC "RPCname" for viewID 2010 but this PhotonView does not exist! View was/is ours. Remote called. By: #01 'name'

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

public class Bullet : MonoBehaviour
{
    public PhotonView PV;
    int dir;

    void Awake()
    {
        PV = GetComponent<PhotonView>();
    }
    void Start() => Destroy(gameObject, 10f);


    void OnTriggerEnter2D(Collider2D col) // col을 RPC의 매개변수로 넘겨줄 수 없다
    {
        if (col.tag == "Border") PV.RPC("DestroyRPC", RpcTarget.AllBuffered);
        if (!PV.IsMine && col.tag == "Player" && col.GetComponent<PhotonView>().IsMine) // 느린쪽에 맞춰서 Hit판정
        {
            col.GetComponent<Player>().Hit();
            PV.RPC("DestroyRPC", RpcTarget.AllBuffered);
        }
    }


    [PunRPC]
    void DirRPC(int dir) => this.dir = dir;

    [PunRPC]
    void DestroyRPC()
    {
        Destroy(gameObject);
    }
}

I'm making a two-player shooter game, and bullets disappear when they hit a wall, but leave a warning message like that.

I asked chatGPT, so he said like this, but It not worked

if (PV != null && PV.IsMine)
英文:

Received RPC "RPCname" for viewID 2010 but this PhotonView does not exist! View was/is ours. Remote called. By: #01 'name'

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

public class Bullet : MonoBehaviour
{
    public PhotonView PV;
    int dir;

    void Awake()
    {
        PV = GetComponent&lt;PhotonView&gt;();
    }
    void Start() =&gt; Destroy(gameObject, 10f);


    void OnTriggerEnter2D(Collider2D col) // col을 RPC의 매개변수로 넘겨줄 수 없다
    {
        if (col.tag == &quot;Border&quot;) PV.RPC(&quot;DestroyRPC&quot;, RpcTarget.AllBuffered);
        if (!PV.IsMine &amp;&amp; col.tag == &quot;Player&quot; &amp;&amp; col.GetComponent&lt;PhotonView&gt;().IsMine) // 느린쪽에 맞춰서 Hit판정
        {
            col.GetComponent&lt;Player&gt;().Hit();
            PV.RPC(&quot;DestroyRPC&quot;, RpcTarget.AllBuffered);
        }
    }


    [PunRPC]
    void DirRPC(int dir) =&gt; this.dir = dir;

    [PunRPC]
    void DestroyRPC()
    {

        Destroy(gameObject);
    }
}

I'm making a two-player shooter game, and bullets disappear when they hit a wall, but leave a warning message like that.

I asked chatGPT, so he said like this, but It not worked

        if (PV != null &amp;&amp; PV.IsMine)

答案1

得分: 0

看起来你完全搞乱了网络对象的工作流程。请阅读Photon Engine的手册,了解如何实例化和删除网络实体。除此之外,以这种方式复制子弹并不是一个好的做法,因为由于浮点精度和网络快照延迟,不同玩家之间会出现各种逻辑争议。更好的做法是拥有一个武器的网络实体,从服务器向其他玩家发送所有射出的子弹的信息。

英文:

It seems like you've completely messing up the workflow of a networked object. Please read the Photon Engine's manual on how to instantiate and delete networked entities. Besides that, it's not a good practice to make your bullets replicated in this way since you'll get all sorts of logic controversy for different players because of a floating point precision and network snapshot delay. It would be much better to have a network entity of a weapon that sends information aboul all bullets shot to other players from server.

huangapple
  • 本文由 发表于 2023年6月29日 14:20:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76578485.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定