- Home /
 
Unity Network Spawn object and follow player
Here is my situation (sorry for the bad english):
I'm creating a simple Multiplayer Pokemon like game (3D). The player is a Third Person Pokemon trainer with his own camera, up to here all right. The thing is that I want to spawn, when the player press a button, a pokemon (NPC) that follows the character which has spawned it. I don't know how to spawn that creature in client/server and I don't know how to make the Pokemon only follows the player who has spawned it.
This is a part of my Network Behaviour where I'm trying to spawn it, but doens't work well.
 public GameObject followerPrefab;
 
 
     void Update () {
 
     if (!isLocalPlayer)
     {
     return;
     }
 
    if (Input.GetKeyDown(KeyCode.F)){
         GameObject pet = Instantiate (followerPrefab, transform.position+(transform.forward*2), transform.rotation);
         NetworkServer.Spawn (pet);
    }
 
 
      }
 
               Any help will be appreciated. Thanks!
Answer by KalleRosendahl · Aug 08, 2018 at 09:21 PM
I would create a script for the "pet" and in there you should store a reference to the owner "GameObject pokemontrainer;" in pet.cs in the update method you can then do something like: follow( pokemontrainer ); the owner you set when spawning your pet, on all clients.. ie. In a rpc call..
Did this on a phone so please bare with me ;)
Your answer
 
             Follow this Question
Related Questions
Networked FindParent 1 Answer
Sending A Variable Over The Network 1 Answer
PlayerIO.com move & synchronisation question 0 Answers
Send RPC in 2 scene 0 Answers
Network.Destroy and collision; destroying correct object. 1 Answer