Search Unity

Third Party Photon PUN Causing issues with OnWillRenderObject()

Discussion in 'Multiplayer' started by ShadowDev_, Feb 19, 2021.

  1. ShadowDev_

    ShadowDev_

    Joined:
    Feb 12, 2021
    Posts:
    1
    So i'm trying to make an AI for scp 173 (works like weeping angels), and It works perfectly fine up until you play multiplayer and only the master client can prevent the AI from moving by staring at it. To me, it looks like there's an issue with when i use OnWillRenderObject(), since that's what is controlling whether it can move or not. Here's my script that controls the movement, any help would be greatly appreciated!
    Code (CSharp):
    1. using Photon.Pun;
    2. using UnityEngine;
    3. using UnityEngine.AI;
    4.  
    5. public class InLineOfSight : MonoBehaviourPun
    6. {
    7.     public float blinkinterval = 4.0f;
    8.     public Renderer render;
    9.     public NavMeshAgent agent;
    10.    
    11.    
    12.     public void Update()
    13.     {
    14.         blinkinterval -= Time.deltaTime;
    15.         if(blinkinterval <= 0f)
    16.         {
    17.             blinkinterval = 4.0f;
    18.         }
    19.        
    20.     }
    21.  
    22.     public void OnWillRenderObject()
    23.     {
    24.             if (blinkinterval > 0.3f)
    25.             {
    26.                 agent.isStopped = true;
    27.             }
    28.             else if (blinkinterval < 0.3f)
    29.             {
    30.                 agent.isStopped = false;
    31.                 Invoke("wait", 0.25f);
    32.             }
    33.     }
    34.  
    35.     public void wait()
    36.     {
    37.         blinkinterval = 4.0f;
    38.     }
    39.    
    40. }
    41.