Hey, Ive been really struggling about the basics of MLAPI, and just wrapping my head around how it works, and Id really appreciate some clarity about a couple things.
-
When calling a ServerRpc, I know Im running that code on the server, but what object is it running in? The Server version of the clients Object?
-
Are networked variables unique to each object using them? Or are they shared? This is the Code Ive been trying to figure it out with.
public NetworkVariableFloat healthy;
public void Takedamage(int dmg)
{
if (IsHost)
{
healthy.Value -= dmg;
return;
}
if (IsClient)
{
HurtHealthyServerRpc(dmg);
return;
}
}
[ServerRpc(RequireOwnership = false)]
public void HurtHealthyServerRpc(float dmg)
{
healthy.Value -= dmg;
}
This treats the healthy variable as separate, and each player has his own healthy.value, which works how I want, but when I try and do it with a team variable.
I want this code to set the host a team 10 and the clients as team 1.
public NetworkVariableFloat teamy;
public void SetTeam()
{
if (IsHost)
{
teamy.Value = 10;
return;
}
if (IsClient)
{
ChangeTeamServerRpc();
return;
}
}
[ServerRpc(RequireOwnership = false)]
public void ChangeTeamServerRpc()
{
teamy.Value = 1;
}
This treats teamy as a shared value, and when either client or host change it, it changes both to the same team and that isnt what I want.
These seems to be written the same way to me though, I dont undersatnd how these are effecting the variables different.
Ive been up all night working on this so if its a easy code fix, sorry, but just missing some of the basics of where code is actually being used at would help a lot.
Thanks