/// <summary> /// Updates the entity from the networked data /// </summary> protected void OnUpdate() { if (!Utilities.IsLevelLoaded()) { return; } if (!m_initialised) { InitialiseAtWorld(); } if (photonView.isMine) { m_health = m_healthBar.HealthLevel; m_mouseCursorAngle = m_cannonController.MouseCursorAngle; if (m_cannonController.CannonsFiredRight) { m_firedCannonsRight = true; } if (m_cannonController.CannonsFiredLeft) { m_firedCannonsLeft = true; } } else if (m_recievedValidData) { PositionNonClientPlayer(); m_cannonController.MouseCursorAngle = m_mouseCursorAngle; if (m_firedCannonsLeft) { m_cannonController.FireWeaponLeft(); m_firedCannonsLeft = false; } if (m_firedCannonsRight) { m_cannonController.FireWeaponRight(); m_firedCannonsRight = false; } if (m_health >= 0) { // Only update health if networked version is lower // This can mean however that networked version thinks its higher // and the entity can be running around seemingly empty // Because of this, initially set if lower but slowly increment if higher // This means if theres a difference it'll eventually correct itself float health = m_healthBar.HealthLevel; if (m_health <= health) { m_healthBar.SetHealthLevel(m_health); } else { float difference = m_health - health; float addSpeed = Time.deltaTime * 0.05f; float incrementingHealth = health + (difference * addSpeed); m_healthBar.SetHealthLevel(incrementingHealth); } } } }