Search Unity

from NetworkMessageInfo.Sender to GameObject

Discussion in 'Scripting' started by dacloo, Nov 18, 2007.

  1. dacloo

    dacloo

    Joined:
    Jun 30, 2005
    Posts:
    469
    Hi!

    When I receive a RPC call, and I know the NetworkMessageInfo.Sender, how do I get to a certain game object?

    For instance, lets say player A presses the spacebar. Then I do a RPC to send everyone in the game the notice: "player A pressed space", and then I want to do a "parent a sphere to the player that pressed the spacebar" on all clients.

    I *think* I can't simply pass a GameObject to the RPC function, because the reference to a game object only is valid on one specific client, right?
     
  2. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    You need to do that parenting on whoever owns both the sphere and the object you are parenting it to.

    So the best bet would prob be an additional RPC call to tell whoever to parent the object.

    If I understood you correctly ;-)
    -Jeremy
     
  3. dacloo

    dacloo

    Joined:
    Jun 30, 2005
    Posts:
    469
    Hmmmm not quite what I ment :)

    Parenting will work but... uhm...
    I mean:
    How do I get a reference to the object I need the sphere to parent to?
    the "other" player?
     
  4. dacloo

    dacloo

    Joined:
    Jun 30, 2005
    Posts:
    469
    Problem solved.

    The trick is to give a unique gameObject name when instantiating, based on the sender ID. When you Network.instantiate, name your objects dynamicly. E.g: player_[player ID].

    And then you can simply refer to them later the same way.