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

How to: Pass booleans through RPC

Discussion in 'Multiplayer' started by Metalloriff, Apr 25, 2016.

  1. Metalloriff

    Metalloriff

    Joined:
    May 8, 2015
    Posts:
    4
    First of all, yes, I know that RPC's are outdated but personally I like the legacy system more.

    So I found a way to pass booleans through RPC easily (without int or other).

    in JS you would do something like this

    var myBool : boolean;

    function Start(){
    var nView = GetComponent.<NetworkView>();
    nView.RPC("MyFunc", RPCMode.AllBuffered, myBool.ToString());
    }

    @RPC
    function MyFunc(b : String){
    if(b == true.ToString()){
    //true would go here
    }
    else{
    //false here
    }
    }


    And I'm not the best with C# but this is probably how it would go


    public Bool myBool;

    void Start(){
    NetworkView nView = GetComponent<NetworkView>(); //not exactly sure how to do local vars in C#
    nView.RPC("MyFunc", RPCMode.AllBuffered, myBool.ToString());
    }

    [RPC]
    void MyFunc(String b){
    if(b == true.ToString()){
    //true would go here
    }
    else{
    //false here
    }
    }

    I'd just figured this out and decided to make a thread for it, hopefully it wasn't just a waist of time.
    Maybe it will help a soul or two.


    :)
     
  2. Oshroth

    Oshroth

    Joined:
    Apr 28, 2014
    Posts:
    99
    The use of the Unity Multiplayer prefix in your topic is confusing, since the prefix is for topics related to the Unet system, not the old legacy system. Also code tags(Insert...->Code) are really handy. [ code=CSharp]blah[ /code] [ code=JavaScript]blah[ /code]
     
  3. Metalloriff

    Metalloriff

    Joined:
    May 8, 2015
    Posts:
    4
    Oh, lol sorry.

    How is the prefix related to Unet? I've never used Unet before in my life, I've always used the legacy system.

    Now you made me confused. xD

    Help me, please.
     
  4. Oshroth

    Oshroth

    Joined:
    Apr 28, 2014
    Posts:
    99