Search Unity

Question [MLAPI] How do I activate code on particular player instances?

Discussion in 'Netcode for GameObjects' started by PastelStoic, May 10, 2021.

  1. PastelStoic

    PastelStoic

    Joined:
    Mar 22, 2020
    Posts:
    4
    Sorry if this is already in the documentation, but I couldn't seem to find it.

    I'm trying to do a few things, but can't figure out how:
    1. Have UI buttons make the player do things
    2. How to have the server access the player gameobjects and check values on each
    3. How to have the server activate commands on particular clients
    4. Other related things I can't put into words right now

    I know it can be done, I'm just a dummyhead and can't figure it out. Help?
     
  2. luke-unity

    luke-unity

    Joined:
    Sep 30, 2020
    Posts:
    306
    1. I'm not sure what there is to say for MLAPI specifically. Your button will call a function when it's pressed. In that function you can call a ServerRpc to run logic on the server.
    2. The server has a copy of all network objects which exist. You can just access the NetworkVariables on the server object.
    3. Use ClientRpcs

    If you need more information on any of those please let me know. I can also recommend the videos from Dapper Dino about MLAPI, they are very beginner friendly: https://docs-multiplayer.unity3d.com/docs/learn/dapper-video
     
  3. PastelStoic

    PastelStoic

    Joined:
    Mar 22, 2020
    Posts:
    4
    I'm mostly referring to the individual players, to control them. I want pressing a button to only activate something for that player, not all players.
     
  4. PastelStoic

    PastelStoic

    Joined:
    Mar 22, 2020
    Posts:
    4
    I figured out how to say what I want to do more clearly.

    Lets say a player is attacking another player. I want to be do something like otherPlayer.TakeDamage() and have it work over the network. How do I do that?