weird bugs

Options
hello im making a zombie escape game but when my player who is a human dies he should be a zombie but when the zombie prefab gets instantiated some bugs happen, so my friend became a zombie and then my screen is red (cause when you are a zombie your screen goes red) and then i hear double of my footsteps, then i look behind me and there is zombie prefab behind me but i can control it, plus it has local gameobject which is not seen by remote.
also when you get spawned as a zombie you cannot get damaged but when you are a human you can.
heres the errors
Illegal view ID:0 method: DoDamage GO:zombie(Clone)
UnityEngine.Debug:LogError(Object)
PhotonView with ID 0 has no method "DoDamage" marked with the [PunRPC](C#) or @PunRPC(JS) property! Args: Single, PhotonPlayer
UnityEngine.Debug:LogError(Object)
NetworkingPeer:ExecuteRpc(Hashtable, Int32) (at Assets/stuff/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3132)
NetworkingPeer:RPC(PhotonView, String, PhotonTargets, PhotonPlayer, Boolean, Object[]) (at Assets/stuff/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:3898)
PhotonNetwork:RPC(PhotonView, String, PhotonTargets, Boolean, Object[]) (at Assets/stuff/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:2934)
PhotonView:RPC(String, PhotonTargets, Object[]) (at Assets/stuff/Photon Unity Networking/Plugins/PhotonNetwork/PhotonView.cs:597)
PlayerDamage:ApplyFallDamage(Single) (at Assets/_Scripts/important scripts/PlayerDamage.cs:86)
UnityEngine.Component:SendMessage(String, Object, SendMessageOptions)
KillZone:OnTriggerEnter(Collider) (at Assets/_Scripts/important scripts/KillZone.cs:10)

my scripts where i think it bugs:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class PlayerNetworkController : Photon.MonoBehaviour
{
    [HideInInspector]
    public string playerName;
    public Transform lookTarget;
    CharacterController cc;
    RoomMultiplayerMenu rmm;
    GameObject currentActiveWeapon;
    public Transform thirdPersonWeapons;
    public Transform shoulderR;
    public Transform shoulderL;
    public CharacterAnimation characterAnimation;
    [System.Serializable]
    public class AnimationSpeed
    {
        public float walkSpeed = 1;
        public float runSpeed = 1;
        public float crouchSpeed = 1;
        public float proneSpeed = 1;
    }
    public AnimationSpeed animationSpeed;
    List<string> mixedAnimations = new List<string>();
    string MovementAnimation;
    string currentBlendedAnimation;
    string currentWeaponName;
    private string currentAnimation = "";
    private string blendedAnimation = "";
    private string prevWeap = "";
    public DrawPlayerName drawPlayerName;
    public PlayerDamage playerDamage;
    public HeadLookController headLookController;
    public List<GameObject> remoteObjectsToDeactivate;
    public List<MonoBehaviour> remoteScriptsToDeactivate;
    public List<GameObject> localObjectsToDeactivate;
    public List<MonoBehaviour> localScriptsToDeactivate;
    [HideInInspector]
    public bool playerIsOurs;
    void Awake()
    {
        if (!photonView.isMine)
        {
            for (int i = 0; i < remoteObjectsToDeactivate.Count; i++)
            {
                remoteObjectsToDeactivate[i].SetActive(false);
            }
            for (int a = 0; a < remoteScriptsToDeactivate.Count; a++)
            {
                //remoteScriptsToDeactivate[a].enabled = false;
                Destroy(remoteScriptsToDeactivate[a]);
            }
            //gameObject.layer = 0;
            gameObject.tag = "Remote";
            if (lookTarget.gameObject.activeSelf == false)
            {
                lookTarget.gameObject.SetActive(true);
            }
        }
        else
        {
            for (int b = 0; b < localObjectsToDeactivate.Count; b++)
            {
                localObjectsToDeactivate[b].SetActive(false);
            }
            for (int c = 0; c < localScriptsToDeactivate.Count; c++)
            {
                //localScriptsToDeactivate[c].enabled = false;
                Destroy(localScriptsToDeactivate[c]);
            }
            Destroy(headLookController);
        }
        rmm = GameObject.FindWithTag("Network").GetComponent<RoomMultiplayerMenu>();
    }
    
    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {
            stream.SendNext(transform.position);
            stream.SendNext(transform.rotation);
            stream.SendNext(gameObject.name);
            stream.SendNext(lookTarget.position);
            stream.SendNext(lookTarget.rotation);
            stream.SendNext((string)PhotonNetwork.player.customProperties["TeamName"]);
            stream.SendNext(characterAnimation.animationSyncHelper);
            stream.SendNext(characterAnimation.animationForHands);
            stream.SendNext(characterAnimation.activeWeapon);
            stream.SendNext(characterAnimation.animationType);
        }
        else
        {
            //controllerScript._characterState = (CharacterState)(int)stream.ReceiveNext();
            correctPlayerPos = (Vector3)stream.ReceiveNext();
            correctPlayerRot = (Quaternion)stream.ReceiveNext();
            PlayerName = (string)stream.ReceiveNext();
            lookTargetPos = (Vector3)stream.ReceiveNext();
            lookTargetRot = (Quaternion)stream.ReceiveNext();
            playerTeam = (string)stream.ReceiveNext();
            currentAnimation = (string)stream.ReceiveNext();
            blendedAnimation = (string)stream.ReceiveNext();
            currentWeaponName = (string)stream.ReceiveNext();
            animType = (string)stream.ReceiveNext();
        }
    }

    private Vector3 correctPlayerPos = new Vector3(0, -100, 0);
    private Quaternion correctPlayerRot = Quaternion.identity;
    private string PlayerName = "";
    private Vector3 lookTargetPos = Vector3.zero;
    private Quaternion lookTargetRot = Quaternion.identity;
    private string playerTeam = "";
    private string animType = "";

    void Update()
    {
        playerIsOurs = photonView.isMine;
        if (!photonView.isMine)
        {
            transform.position = Vector3.Lerp(transform.position, correctPlayerPos, Time.deltaTime * 8);
            transform.rotation = Quaternion.Lerp(transform.rotation, correctPlayerRot, Time.deltaTime * 8);
            lookTarget.position = Vector3.Lerp(lookTarget.position, lookTargetPos, Time.deltaTime * 8);
            lookTarget.rotation = lookTargetRot;

            if (gameObject.name != PlayerName)
            {
                gameObject.name = PlayerName;
            }
            if (rmm.gameMode == "TDM")
            {
                if (playerTeam == (string)PhotonNetwork.player.customProperties["TeamName"])
                {
                    playerDamage.disableDamage = true;
                    drawPlayerName.enabled = true;
                }
                else
                {
                    playerDamage.disableDamage = false;
                    drawPlayerName.enabled = false;
                }
            }
            if (rmm.gameMode == "ZOM")
            {
                if (playerTeam == (string)PhotonNetwork.player.customProperties["TeamName"])
                {
                    playerDamage.disableDamage = true;
                    drawPlayerName.enabled = true;
                }
                else
                {
                    playerDamage.disableDamage = false;
                    drawPlayerName.enabled = false;
                }
            }
            else
            {
                drawPlayerName.enabled = false;
            }
            if (MovementAnimation != currentAnimation)
            {
                MovementAnimation = currentAnimation;
                if (animType == "Walking")
                {
                    headLookController.GetComponent<Animation>()[MovementAnimation].speed = animationSpeed.walkSpeed;
                }
                if (animType == "Running")
                {
                    headLookController.GetComponent<Animation>()[MovementAnimation].speed = animationSpeed.runSpeed;
                }
                if (animType == "Crouch")
                {
                    headLookController.GetComponent<Animation>()[MovementAnimation].speed = animationSpeed.crouchSpeed;
                }
                if (animType == "Prone")
                {
                    headLookController.GetComponent<Animation>()[MovementAnimation].speed = animationSpeed.proneSpeed;
                }
                if (headLookController.GetComponent<Animation>()[MovementAnimation] != null)
                {
                    headLookController.GetComponent<Animation>()[MovementAnimation].layer = 1;
                    headLookController.GetComponent<Animation>()[MovementAnimation].wrapMode = WrapMode.Loop;
                }
            }
            if (headLookController.GetComponent<Animation>()[MovementAnimation] != null)
            {
                headLookController.GetComponent<Animation>().CrossFade(MovementAnimation);
            }
            if (currentBlendedAnimation != blendedAnimation)
            {
                currentBlendedAnimation = blendedAnimation;
                if (!mixedAnimations.Contains(currentBlendedAnimation) && currentBlendedAnimation != "Null" && headLookController.GetComponent<Animation>()[currentBlendedAnimation] != null)
                {
                    headLookController.GetComponent<Animation>()[currentBlendedAnimation].layer = 4;
                    headLookController.GetComponent<Animation>()[currentBlendedAnimation].wrapMode = WrapMode.Loop;
                    headLookController.GetComponent<Animation>()[currentBlendedAnimation].AddMixingTransform(shoulderR);
                    headLookController.GetComponent<Animation>()[currentBlendedAnimation].AddMixingTransform(shoulderL);
                    mixedAnimations.Add(currentBlendedAnimation);
                }
            }
            if (currentBlendedAnimation != "Null" && headLookController.GetComponent<Animation>()[currentBlendedAnimation] != null)
            {
                headLookController.GetComponent<Animation>().Play(currentBlendedAnimation);
            }
            if (prevWeap != currentWeaponName)
            {
                for (int i = 0; i < thirdPersonWeapons.childCount; i++)
                {
                    if (thirdPersonWeapons.GetChild(i).name != currentWeaponName)
                    {
                        thirdPersonWeapons.GetChild(i).gameObject.SetActive(false);
                    }
                    else
                    {
                        thirdPersonWeapons.GetChild(i).gameObject.SetActive(true);
                        currentActiveWeapon = thirdPersonWeapons.GetChild(i).gameObject;
                    }
                }
                prevWeap = currentWeaponName;
            }
        }
    }

    public void ReDeactivatePlayerObjects()
    {
        if (photonView.isMine)
        {
            for (int b = 0; b < localObjectsToDeactivate.Count; b++)
            {
                localObjectsToDeactivate[b].SetActive(false);
            }
            for (int c = 0; c < localScriptsToDeactivate.Count; c++)
            {
                //localScriptsToDeactivate[c].enabled = false;
                Destroy(localScriptsToDeactivate[c]);
            }
        }
    }
    public void syncMachineGun(float errorAngle)
    {
        photonView.RPC("SyncWeaponsRPC", PhotonTargets.Others, "syncMachineGun", errorAngle);
    }

    public void syncShotGun(int fractions)
    {
        photonView.RPC("SyncWeaponsRPC", PhotonTargets.Others, "syncShotGun", (float)fractions);
    }

    public void syncGrenadeLauncher(float initialSpeed)
    {
        photonView.RPC("SyncWeaponsRPC", PhotonTargets.Others, "syncGrenadeLauncher", initialSpeed);
    }

    public void syncKnife()
    {
        photonView.RPC("SyncWeaponsRPC", PhotonTargets.Others, "syncKnife", 0.0f);
    }

    [PunRPC]
    void SyncWeaponsRPC(string functionName, float Value)
    {
        if (currentActiveWeapon)
        {
            currentActiveWeapon.SendMessage(functionName, Value, SendMessageOptions.DontRequireReceiver);
        }
    }
}

Comments

  • Federico123
    Options
    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    using Hashtable = ExitGames.Client.Photon.Hashtable;
    
    public class PlayerDamage : Photon.MonoBehaviour
    {
        public GUISkin guiSKin;
        public float hp = 100;
        public GameObject ragdoll;
        public Texture2D hitMarkTexture;
        //public FPScontroller Player;
        public BleedBehavior screenblood;
        [SerializeField]
        private float damageBloodAmount = 3f;
        [SerializeField]
        private float maxBloodIndication = 0.5f;
        int teamLives = 12;
        [System.Serializable]
        public class HitBoxes
        {
            public Collider box;
            public float damage;
            public string message;
            public HitBoxes(Collider box1, float damage1, string message1)
            {
                box = box1;
                damage = damage1;
                message = message1;
            }
        }
        public List<HitBoxes> hitBoxes = new List<HitBoxes>();
        [HideInInspector]
        public float currentHp;
        Quaternion camRot;
        Quaternion camDefaultRotation;
        float fadeValue;
        float fadeValueB;
        [HideInInspector]
        public bool disableDamage = false;
        bool weKilled;
        RoomMultiplayerMenu rmm;
        GameObject networkObject;
    
        void Awake()
        {
            currentHp = hp;
            if (!photonView.isMine)
            {
                for (int i = 0; i < hitBoxes.Count; i++)
                {
                    hitBoxes[i].box.gameObject.AddComponent<HitBox>();
                    hitBoxes[i].box.gameObject.GetComponent<HitBox>().maxDamage = hitBoxes[i].damage;
                    hitBoxes[i].box.gameObject.GetComponent<HitBox>().playerDamage = this;
                    hitBoxes[i].box.isTrigger = false;
                }
            }
            else
            {
                camDefaultRotation = Camera.main.transform.localRotation;
                for (int a = 0; a < hitBoxes.Count; a++)
                {
                    Destroy(hitBoxes[a].box.GetComponent<Collider>());
                }
                hitBoxes.Clear();
            }
    
            networkObject = GameObject.FindWithTag("Network");
            rmm = networkObject.GetComponent<RoomMultiplayerMenu>();
        }
    
        void Update()
        {
            fadeValue = Mathf.Lerp(fadeValue, 0, Time.deltaTime * 2);
            fadeValueB = Mathf.Lerp(fadeValueB, 0, Time.deltaTime * 2);
            //Player.movement.WalkSpeed = Player.movement.WalkSpeed * (currentHp / 99.9f);
            //Player.movement.RunSpeed = Player.movement.RunSpeed * (currentHp / 99.9f);
            if (Camera.main)
                Camera.main.transform.localRotation = Quaternion.Slerp(Camera.main.transform.localRotation, camRot, Time.deltaTime * 15);
        }
    
        public void ApplyFallDamage(float damage)
        {
            if (photonView.isMine)
            {
                photonView.RPC("DoDamage", PhotonTargets.All, damage, PhotonNetwork.player);
            }
        }
        public void TotalDamage(float damage)
        {
            if (disableDamage)
                return;
            fadeValue = 2;
            photonView.RPC("DoDamage", PhotonTargets.All, damage, PhotonNetwork.player);
        }
    
        [PunRPC]
        void DoDamage(float damage, PhotonPlayer player)
        {
            screenblood.minAlpha += Mathf.Clamp01(damageBloodAmount * (int)currentHp / currentHp);
            if (weKilled)
                return;
            if (currentHp > 0 && photonView.isMine)
            {
                this.StopAllCoroutines();
                StartCoroutine(doCameraShake());
            }
            fadeValueB = 2;
            currentHp -= damage;
            if (currentHp < 0)
            {
                for (int i = 0; i < transform.childCount; i++)
                {
                    transform.GetChild(i).gameObject.SetActive(false);
                }
                GameObject temp;
                temp = Instantiate(ragdoll, transform.position, transform.rotation) as GameObject;
    
                if (!photonView.isMine)
                {
                    temp.SendMessage("clearCamera");
                    if (PhotonNetwork.player == player)
                    {
                        networkObject.SendMessage("AddKillNotification", gameObject.name, SendMessageOptions.DontRequireReceiver);
                        int teamScore = new int();
                        if ((string)PhotonNetwork.player.customProperties["TeamName"] == rmm.team_a.teamName)
                        {
                            int totalKIlls = (int)PhotonNetwork.player.customProperties["Kills"];
                            totalKIlls++;
                            Hashtable setPlayerKills = new Hashtable() { { "Kills", totalKIlls } };
                            PhotonNetwork.player.SetCustomProperties(setPlayerKills);
                        }
    
                        if ((string)PhotonNetwork.player.customProperties["TeamName"] == rmm.team_b.teamName)
                        {
                            teamScore = (int)PhotonNetwork.room.customProperties["Team1Score"];
                            teamScore--;
                            Hashtable setTeam1Score = new Hashtable() { { "Team1Score", teamScore } };
                            PhotonNetwork.room.SetCustomProperties(setTeam1Score);
                            int totalKIlls = (int)PhotonNetwork.player.customProperties["Kills"];
                            totalKIlls++;
                            Hashtable setPlayerKills = new Hashtable() { { "Kills", totalKIlls } };
                            PhotonNetwork.player.SetCustomProperties(setPlayerKills);
                        }
                    }
                }
                else
                {
                    print("We got killed");
                    temp.SendMessage("RespawnAfter");
                    //PhotonNetwork.player.SetCustomProperties(setPlayerTeam);
                    int totalDeaths = (int)PhotonNetwork.player.customProperties["Deaths"];
                    totalDeaths++;
                    Hashtable setPlayerDeaths = new Hashtable() { { "Deaths", totalDeaths } };
                    PhotonNetwork.player.SetCustomProperties(setPlayerDeaths);
                    StartCoroutine(DestroyPlayer(0.0f));
                    if (PhotonNetwork.player == player)
                    {
                        networkObject.SendMessage("PlayerFellDown", PhotonNetwork.player.name, SendMessageOptions.DontRequireReceiver);
                        teamLives = (int)PhotonNetwork.room.customProperties["Team1Score"];
                        teamLives--;
                        Hashtable setTeam1Score_fell = new Hashtable() { { "Team1Score", teamLives } };
                        PhotonNetwork.room.SetCustomProperties(setTeam1Score_fell);
                    }
                }
                currentHp = 0;
                weKilled = true;
            }
        }
    
        IEnumerator DestroyPlayer(float delay)
        {
            yield return new WaitForSeconds(delay);
            PhotonNetwork.Destroy(gameObject);
        }
    
        void SwapTeams()
        {
            photonView.RPC("DoSwapTeams", PhotonTargets.All);
        }
    
        [PunRPC]
        void DoSwapTeams()
        {
            GameObject temp;
            temp = Instantiate(ragdoll, transform.position, transform.rotation) as GameObject;
            if (photonView.isMine)
            {
                temp.SendMessage("RespawnAfter");
                StartCoroutine(DestroyPlayer(0));
            }
            else
            {
                temp.SendMessage("clearCamera");
            }
        }
    
        void OnGUI()
        {
            if (photonView.isMine)
            {
                GUI.skin = guiSKin;
                GUI.color = new Color(1, 1, 1, 0.9f);
                GUI.depth = 10;
                GUI.color = new Color(1, 1, 1, 0.9f);
                GUI.Box(new Rect(Screen.width - 220, Screen.height - 55, 100, 45), "HP " + (int)currentHp);
            }
            else
            {
                GUI.color = new Color(1, 1, 1, fadeValue);
                GUI.DrawTexture(new Rect(Screen.width / 2 - 13, Screen.height / 2 - 13, 26, 26), hitMarkTexture, ScaleMode.StretchToFill);
            }
        }
    
        IEnumerator doCameraShake()
        {
            camRot = Quaternion.Euler(Random.Range(-10, 10), Random.Range(-10, 10), 0);
            yield return new WaitForSeconds(0.1f);
            camRot = camDefaultRotation;
        }
    }
    
  • Federico123
    Options
    oh forgot to say this, if you die by a kill zone you will not respawn but for other players the zombie will be spawned (which is you) but you dont see it
  • Federico123
    Options
    https://youtu.be/8i9L10Xjomk heres the video to show the bug.
    i also founded something really interesting.
    when i slowed down the video i saw this:
    https://i.imgur.com/3RR4bLS.jpg
    so it does actually spawn which explains the sound of the announcer saying "another zombie is coming"
    but it deletes, kinda weird but interesting at the same time