Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

RPC call *sorta* not working...

Discussion in 'Multiplayer' started by Lab013, Aug 2, 2009.

  1. Lab013

    Lab013

    Joined:
    Oct 22, 2008
    Posts:
    405
    Ok so I am making a simple networking FPS, and I am trying to detect when a player has been shot, I can figure out who has been shot, but after that nothing is really working...

    So I have a script that just does a raycast to figure out if you shot someone, if you did, then it sends out a RPC call, to figure out who has been shot, and to cause a reaction.

    This is the RPC call
    Code (csharp):
    1. @RPC
    2. function YourDead(n : NetworkViewID, _name : String) {
    3.     if (n.isMine) {
    4.         chat.networkView.RPC("ApplyGlobalChatText", RPCMode.All, "*************" + PlayerPrefs.GetString("name") + " Has been shot by: " + _name, 1);
    5.         transform.GetComponent(GunController).hasBeenHit = true;
    6.         transform.position = GameObject.FindWithTag("Respawn").transform.position;
    7.         yield WaitForSeconds(3);
    8.         transform.GetComponent(GunController).hasBeenHit = false;
    9.     }
    10. }
    It is able to tell who has been shot, and calls the actual code inside the if statement, however the chat.networkView.RPC... is the only thing that really works. Changing the transforms position doesn't work, and changing the boolean value doesn't work, anyone know what I am doing wrong?
     
  2. Lab013

    Lab013

    Joined:
    Oct 22, 2008
    Posts:
    405
    Anyone know?
     
  3. carbonization

    carbonization

    Joined:
    Mar 23, 2009
    Posts:
    37
    Check to make sure that FindWithTag() GetComponent() are returning objects.
     
  4. DrHotbunz

    DrHotbunz

    Joined:
    Feb 14, 2009
    Posts:
    315
    Lets see your RPC call of YourDead.
     
  5. Lab013

    Lab013

    Joined:
    Oct 22, 2008
    Posts:
    405
    Sorry it took me so long to respond, I did however finally figure it out.

    Originally my RPC call was like this

    transform.networkView.RPC("YourDead", RPCMode.Others, hit.transform.networkView.viewID, tmp);

    I figured out though that I needed to change it to

    hit.transform.networkView.RPC("YourDead", RPCMode.Others, hit.transform.networkView.viewID, tmp); // hit is a RaycastHit.
     
  6. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    good to hear that you are up now :)