33 lines
961 B
C#
33 lines
961 B
C#
using Unity.FPS.Game;
|
|
using Unity.FPS.Gameplay;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Unity.FPS.UI
|
|
{
|
|
public class StanceHUD : MonoBehaviour
|
|
{
|
|
[Tooltip("Image component for the stance sprites")]
|
|
public Image StanceImage;
|
|
|
|
[Tooltip("Sprite to display when standing")]
|
|
public Sprite StandingSprite;
|
|
|
|
[Tooltip("Sprite to display when crouching")]
|
|
public Sprite CrouchingSprite;
|
|
|
|
void Start()
|
|
{
|
|
PlayerCharacterController character = FindFirstObjectByType<PlayerCharacterController>();
|
|
DebugUtility.HandleErrorIfNullFindObject<PlayerCharacterController, StanceHUD>(character, this);
|
|
character.OnStanceChanged += OnStanceChanged;
|
|
|
|
OnStanceChanged(character.IsCrouching);
|
|
}
|
|
|
|
void OnStanceChanged(bool crouched)
|
|
{
|
|
StanceImage.sprite = crouched ? CrouchingSprite : StandingSprite;
|
|
}
|
|
}
|
|
} |