1
\$\begingroup\$

I am developing multiplayer game in unity. For multiplayer i am using photon networking library. I created room and join client successfully.

But Problem is I am doing gameobject movent by this code:

public GameObject player;
IEnumerator Moving (String temp)
{

    for (int i = 0; i < 3; i++) {

        player.transform.DOMove (CurrentPositionHolder, 0.5f).SetEase 
           (Ease.Linear);   
        yield return new WaitForSeconds (0.5f);
    }
}

DoMoveis library here.

Problem is player movement is not synchronized.

For Synchronization I add photonview component to player gameobject.

And i call coroutine though RPC like this.

player.GetComponent<PhotonView>().RPC ("Moving", PhotonTargets.All, "temp");

Accordingly i changed coroutine like this:

[PunRPC]
IEnumerator Moving (String temp)
{

    for (int i = 0; i < 3; i++) {

        player.transform.DOMove (CurrentPositionHolder, 0.5f).SetEase 
           (Ease.Linear);   
        yield return new WaitForSeconds (0.5f);
    }
}

I got this error

Illegal view ID:0 method: Moving GO:player UnityEngine.Debug:LogError(Object)

\$\endgroup\$
  • \$\begingroup\$ Are you instantiating the object using PhotonNetwork.Instantiate? \$\endgroup\$ – MichaelHouse Dec 13 '17 at 18:21
  • \$\begingroup\$ No, I instantiate it normally, Is it required to instantiate like that? \$\endgroup\$ – Rupal Patel Dec 13 '17 at 18:26
  • \$\begingroup\$ As far as I know, it is. Check out the tutorial documentation. \$\endgroup\$ – MichaelHouse Dec 13 '17 at 18:43
  • \$\begingroup\$ I instantiate using PhotonNetwork.Instantiate, Error message not showing but if gameobject on client side move, it not showing at server side and vice-versa. I want sync it. \$\endgroup\$ – Rupal Patel Dec 13 '17 at 19:41
  • 1
    \$\begingroup\$ We'd need more details if you want that solved. Try making one of the tutorials work for you first, then apply what you learn to your project. \$\endgroup\$ – MichaelHouse Dec 13 '17 at 19:57
0
\$\begingroup\$

Problem gets solved. I call Moving enumerator from method not directly using RPC. And Make method call using RPC.

And Most important thing is use transfrom instead of gameobject like this:

transform.DOMove (CurrentPositionHolder, 0.5f).SetEase(Ease.Linear);   
\$\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.