How to make npc in unity

edited October 2013 in Any Topic & Chat
Hi, how can I make npc in unity using photon cloud. I have basic npc movement script but I want to random choose waypoint and to tell all players that npc is moving to gameobject. Thanks


  • One way would be to let the Master Client run the AI to pick a waypoint as target. When it does, the AI also sends an RPC to the other clients to tell them about the new target. All clients move the NPC independently to the new target.
    Alternatively you can "observe" a script on the NPC GameObject's PhotonView. In this case, the script should send the target when it changed. You don't need to send something in OnPhotonSerializeView() every time this gets called.
  • Thanks for answer, but if I use PhotonView to observe a script, for example if I have "public int RandomNum" will it change that number on all clients? And what if on one client we set "RandomNum=1" and on other to "2".
    -I guess I need to use master client?
  • The observed script should contain the OnPhotonSerializeView() method. This method is called with a "stream" of incoming data to read from. Only the owner of the GameObject will be able to write to that stream. You can use this to sync your data (like the random number).
    With this setup, no client will set another random value than others. Only the owner is modifying it's values by the stream.
Sign In or Register to comment.