mirror of
https://github.com/Dadechin/Unity-WebSocket.git
synced 2025-07-21 20:54:34 +00:00
41 lines
1.0 KiB
C#
41 lines
1.0 KiB
C#
|
#if !FISHNET_STABLE_REPLICATESTATES
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
namespace FishNet.Demo.Prediction.CharacterControllers
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// This is a basic implementation of hooking up the UI to the owners character stamina.
|
|||
|
/// </summary>
|
|||
|
public class StaminaCanvas : MonoBehaviour
|
|||
|
{
|
|||
|
[SerializeField]
|
|||
|
private Image _staminaBar;
|
|||
|
|
|||
|
private CharacterControllerPrediction _character;
|
|||
|
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
CharacterControllerPrediction.OnOwner += CCP_OnOwner;
|
|||
|
}
|
|||
|
|
|||
|
private void OnDestroy()
|
|||
|
{
|
|||
|
CharacterControllerPrediction.OnOwner -= CCP_OnOwner;
|
|||
|
}
|
|||
|
|
|||
|
private void Update()
|
|||
|
{
|
|||
|
if (_character == null) return;
|
|||
|
|
|||
|
float fillAmount = (_character.Stamina / CharacterControllerPrediction.Maximum_Stamina);
|
|||
|
_staminaBar.fillAmount = fillAmount;
|
|||
|
}
|
|||
|
|
|||
|
private void CCP_OnOwner(CharacterControllerPrediction ccp)
|
|||
|
{
|
|||
|
_character = ccp;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
#endif
|