- Home /
Question by
TomatJuice · Jul 07, 2020 at 12:41 PM ·
2dnetworkingmultiplayermultiplayer-networkingspriterenderer
Syncing SpriteRenderer Between Clients
For the host of the server, which is also a client, they can see any of the custom sprites that are on the newly joined clients. But, the newly joined client can't see it's own sprite nor can it see the host sprites. What is a way this can be fixed?
public enum Class { Spreadshot, Burstshot, Sharpshot, Bigshot, Splashshot, Lobshot }
public Class classes;
[Space]
[HideInInspector]
public BaseClassStats baseStats;
StatsManager statsManager;
public SpriteRenderer sprite;
public SliderUI healthBar;
[Space]
[Range(0, 5)]
public float health;
[Range(0, 5)]
public float damage;
[Range(0, 5)]
public float speed;
[Range(0, 5)]
public float range;
[Range(0, 5)]
public float reload;
[HideInInspector]
public float healthCal;
[HideInInspector]
public float damageCal;
[HideInInspector]
public float speedCal;
[HideInInspector]
public float rangeCal;
[HideInInspector]
public float reloadCal;
private void Awake()
{
statsManager = StatsManager.instance;
}
private void Start()
{
if (!isLocalPlayer)
return;
CmdGetStats();
}
[Command]
void CmdGetStats()
{
GetBaseClassStats();
CalculateStats();
SetPhysicalStats();
}
[Server]
void GetBaseClassStats()
{
if (classes == Class.Spreadshot)
{
baseStats = statsManager.spreadshot;
}
if (classes == Class.Burstshot)
{
baseStats = statsManager.burstshot;
}
if (classes == Class.Sharpshot)
{
baseStats = statsManager.sharpshot;
}
if (classes == Class.Bigshot)
{
baseStats = statsManager.bigshot;
}
if (classes == Class.Splashshot)
{
baseStats = statsManager.splashshot;
}
if (classes == Class.Lobshot)
{
baseStats = statsManager.lobshot;
}
}
[Server]
void CalculateStats()
{
healthCal = health * baseStats.healthMulti;
damageCal = damage * baseStats.healthMulti;
speedCal = speed * baseStats.speedMulti;
rangeCal = range * baseStats.rangeMulti;
reloadCal = reload * baseStats.reloadMulti;
healthBar.CmdSetMaxValue(healthCal);
}
[Server]
void SetPhysicalStats()
{
sprite.sprite = baseStats.classSprite;
sprite.color = baseStats.spriteColor;
}
private void Update()
{
healthBar.SetValue(healthCal);
}
Comment
Your answer
Follow this Question
Related Questions
Detecting when the other player presses a button 1 Answer
Unity networking tutorial? 6 Answers
Simpler way to do 2D multiplayer? 2 Answers
Controlling a network game? 0 Answers
Unity NetworkTransformChild - Syncing the Child of a Child 0 Answers