0
\$\begingroup\$

objective: I have a player which instantiate by network manager class. I want to map/sync its position/rotation to another object which is also instantiate by my player object.

(what it i have tried) Below code is attached to my network player which instantiating another object (mimic object)

         void Start() {
                if (isLocalPlayer)
                {
                    CmdInstantiate();
    }

         [Command]
            void CmdInstantiate()
            {
                // This [Command] code is run on the server!
                mimic = (GameObject)Instantiate(
                     mimicObject);
                // spawn the bullet on the clients
                NetworkServer.Spawn(mimic);
            }

void Update()
    {
        if (!isLocalPlayer) {

            return; 
        }
        CmdMimicObjectPosSync();//updating position on server
    }

   [Command]
    void CmdMimicObjectPosSync()
    {//position sync method
        mimic.transform.position = this.transform.position;
        mimic.transform.GetChild(0).position = this.transform.GetChild(0).position;
        mimic.transform.GetChild(1).position = this.transform.GetChild(1).position;
        mimic.transform.GetChild(2).position = this.transform.GetChild(2).position;
    }

it is working fine on the player side but another player who has joined the network unable to see it although mimic object has instantiated but its value remains same (no change). Mimic object has attached network identity and network transform.

\$\endgroup\$
0
\$\begingroup\$

Each object that you want to instantiate over network must need to be added in Register spawn able list of Network Manager . By adding mimic object into spawnable list i am managed map one object postion/rotation to another object.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.