Photon“失败了网络回形'游戏对象

发布于 2025-02-02 00:59:49 字数 2216 浏览 4 评论 0原文

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

public class Player1 : MonoBehaviour
{

    public int maxHealth = 100;
    public int currentHealth = 100;
    PhotonView myPhotonView;
    public HealthBar healthBar;
    public GameObject Controller;

    void Start()
    {
        
        healthBar.SetMaxHealth(maxHealth);
    }


    public void TakeDamage(int damage)
    {
        if (!myPhotonView.IsMine)
        {
            currentHealth -= damage;
            Debug.Log(currentHealth);
            
            if (currentHealth <= 0)
            {
                Kill();
            }
        }
    }

    public void Kill()
    {
        if (!myPhotonView.IsMine)
        {
            PhotonNetwork.Destroy(gameObject);
        }
    }

    void OnCollisionEnter(Collision collision)
    {

        myPhotonView = GetComponent<PhotonView>();

        if (!myPhotonView.IsMine)
        {

            {
                if (collision.gameObject.tag == "Bullet")
                {
                    Destroy(collision.gameObject);
                    TakeDamage(20);
                    Debug.Log("Collision Detected");
                }

                if (collision.gameObject.tag == "Bullet2")
                {
                    Destroy(collision.gameObject);
                    TakeDamage(40);
                    Debug.Log("Collision Detected");
                }

                if (collision.gameObject.tag == "Bullet3")
                {
                    Destroy(collision.gameObject);
                    TakeDamage(50);
                    Debug.Log("Collision Detected");
                }

                if (collision.gameObject.tag == "Bullet4")
                {
                    Destroy(collision.gameObject);
                    TakeDamage(100);
                    Debug.Log("Collision Detected");
                }
            }
        }
    }
}

每当我尝试删除死亡的播放器时,我都会遇到此错误。

都无法“网络删除” GameObject。客户既不是所有者,也不是Masterclient接管离开的所有者:在玩家(克隆)上查看(0)2001

我尝试过所有工作来制作这项工作,这只是我不知道它与Photon View有关系,但我只是无法弄清楚。

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

public class Player1 : MonoBehaviour
{

    public int maxHealth = 100;
    public int currentHealth = 100;
    PhotonView myPhotonView;
    public HealthBar healthBar;
    public GameObject Controller;

    void Start()
    {
        
        healthBar.SetMaxHealth(maxHealth);
    }


    public void TakeDamage(int damage)
    {
        if (!myPhotonView.IsMine)
        {
            currentHealth -= damage;
            Debug.Log(currentHealth);
            
            if (currentHealth <= 0)
            {
                Kill();
            }
        }
    }

    public void Kill()
    {
        if (!myPhotonView.IsMine)
        {
            PhotonNetwork.Destroy(gameObject);
        }
    }

    void OnCollisionEnter(Collision collision)
    {

        myPhotonView = GetComponent<PhotonView>();

        if (!myPhotonView.IsMine)
        {

            {
                if (collision.gameObject.tag == "Bullet")
                {
                    Destroy(collision.gameObject);
                    TakeDamage(20);
                    Debug.Log("Collision Detected");
                }

                if (collision.gameObject.tag == "Bullet2")
                {
                    Destroy(collision.gameObject);
                    TakeDamage(40);
                    Debug.Log("Collision Detected");
                }

                if (collision.gameObject.tag == "Bullet3")
                {
                    Destroy(collision.gameObject);
                    TakeDamage(50);
                    Debug.Log("Collision Detected");
                }

                if (collision.gameObject.tag == "Bullet4")
                {
                    Destroy(collision.gameObject);
                    TakeDamage(100);
                    Debug.Log("Collision Detected");
                }
            }
        }
    }
}

Whenever I try to remove a player that has died I get this error.

Failed to 'network-remove' GameObject. Client is neither owner nor masterClient taking over for owner who left: View (0)2001 on Player(Clone)

I've tried everything to make this work it just won't I know it has something to do with photon view but I just can't figure it out.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

思念满溢 2025-02-09 00:59:49

因为您不是对象或主客户端的所有者,因此您无法摧毁该对象。

您可以将RPC发送给主客户端,以询问主销毁它。

Because you are not owner of object or master client, so you can not destroy that object.

You can send RPC to master client to ask master destroy it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文