Skip to content

Instantly share code, notes, and snippets.

@SocketWeaver
Created June 17, 2019 00:45
Show Gist options
  • Save SocketWeaver/ef4a73ac4b101e4ac6c91a1f107c7ac3 to your computer and use it in GitHub Desktop.
Save SocketWeaver/ef4a73ac4b101e4ac6c91a1f107c7ac3 to your computer and use it in GitHub Desktop.
Extracted and synchronized player's firing state
void Update()
{
timer += Time.deltaTime;
if (timer >= effectDisplayTime)
{
gunEffect.StopEffects();
}
if (networkID.IsMine)
{
// for the local player, we modify the SyncProperty when the firing value changes.
if (currentFiringValue != lastUpdateFiringValue)
{
syncPropertyAgent.Modify(MACHINE_GUN_FIRING, currentFiringValue);
lastUpdateFiringValue = currentFiringValue;
}
}
else
{
// for the remote copy, we ready from the SyncProperty and fire.
currentFiringValue = syncPropertyAgent.GetPropertyWithName(MACHINE_GUN_FIRING).GetBoolValue();
if (currentFiringValue && timer >= TimeBetweenBullets)
{
DoFire();
}
}
}
public void Fire()
{
currentFiringValue = true;
if (networkID.IsMine)
{
if (timer >= TimeBetweenBullets && Ammo > 0)
{
DoFire();
}
else
{
currentFiringValue = false;
}
}
}
public void StopFiring()
{
if (networkID.IsMine)
{
currentFiringValue = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment