PhotonView不存在。

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

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'

  1. using Photon.Pun;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class Bullet : MonoBehaviour
  6. {
  7. public PhotonView PV;
  8. int dir;
  9. void Awake()
  10. {
  11. PV = GetComponent<PhotonView>();
  12. }
  13. void Start() => Destroy(gameObject, 10f);
  14. void OnTriggerEnter2D(Collider2D col) // col을 RPC의 매개변수로 넘겨줄 수 없다
  15. {
  16. if (col.tag == "Border") PV.RPC("DestroyRPC", RpcTarget.AllBuffered);
  17. if (!PV.IsMine && col.tag == "Player" && col.GetComponent<PhotonView>().IsMine) // 느린쪽에 맞춰서 Hit판정
  18. {
  19. col.GetComponent<Player>().Hit();
  20. PV.RPC("DestroyRPC", RpcTarget.AllBuffered);
  21. }
  22. }
  23. [PunRPC]
  24. void DirRPC(int dir) => this.dir = dir;
  25. [PunRPC]
  26. void DestroyRPC()
  27. {
  28. Destroy(gameObject);
  29. }
  30. }

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

  1. 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'

  1. using Photon.Pun;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class Bullet : MonoBehaviour
  6. {
  7. public PhotonView PV;
  8. int dir;
  9. void Awake()
  10. {
  11. PV = GetComponent&lt;PhotonView&gt;();
  12. }
  13. void Start() =&gt; Destroy(gameObject, 10f);
  14. void OnTriggerEnter2D(Collider2D col) // col을 RPC의 매개변수로 넘겨줄 수 없다
  15. {
  16. if (col.tag == &quot;Border&quot;) PV.RPC(&quot;DestroyRPC&quot;, RpcTarget.AllBuffered);
  17. if (!PV.IsMine &amp;&amp; col.tag == &quot;Player&quot; &amp;&amp; col.GetComponent&lt;PhotonView&gt;().IsMine) // 느린쪽에 맞춰서 Hit판정
  18. {
  19. col.GetComponent&lt;Player&gt;().Hit();
  20. PV.RPC(&quot;DestroyRPC&quot;, RpcTarget.AllBuffered);
  21. }
  22. }
  23. [PunRPC]
  24. void DirRPC(int dir) =&gt; this.dir = dir;
  25. [PunRPC]
  26. void DestroyRPC()
  27. {
  28. Destroy(gameObject);
  29. }
  30. }

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

  1. 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:

确定