Created
June 17, 2019 00:45
-
-
Save SocketWeaver/ef4a73ac4b101e4ac6c91a1f107c7ac3 to your computer and use it in GitHub Desktop.
Extracted and synchronized player's firing state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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