x


Problem with RPC life

Hi, I have a function that if I hit a player call an RPC that change the life of the hit player over the network, this is my code:

int damage = Random.Range(5, 15);

Debug.Log("Calling setlife with value: " + (hit.collider.transform.parent.gameObject.GetComponent().life - damage));

hit.collider.transform.parent.gameObject.GetComponent().RPC("SetLife", PhotonTargets.AllBuffered, (hit.collider.transform.parent.gameObject.GetComponent().life - damage), gameObject.transform);

And this is my RPC:

[RPC]

    void SetLife(int lifeNew, Transform killer)
    {

        if (lifeNew > 0)
        {

            gameObject.GetComponent<PlayerNetwork>().life = lifeNew;

        }

        else
        {

            Debug.Log("E' morto!");
            gameObject.GetComponent<PlayerNetwork>().life = 0;
            gameObject.GetComponent<PhotonView>().RPC("RespawnPlayer", PhotonTargets.AllBuffered, killer);


        }

    }

If I hit a player in my local player editor I see that the other player's life is changed, but in the other game window (the one where is playing the player who was hit), his life doesn't change.

Why?

more ▼

asked Feb 12 '12 at 07:46 PM

marf gravatar image

marf
16 5 6 8

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1175
x710
x682
x237
x30

asked: Feb 12 '12 at 07:46 PM

Seen: 394 times

Last Updated: Feb 12 '12 at 07:46 PM