45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BrewMonster.UI
|
|
{
|
|
/// <summary>
|
|
/// HUD button: pick up the nearest ground item or money (host trace + TryPickupNearestGroundMatter).
|
|
/// Assign to a Button or leave unassigned to use the component's own Button.
|
|
/// </summary>
|
|
public class PickupNearestButtonHandler : MonoBehaviour
|
|
{
|
|
[SerializeField] private Button button;
|
|
[Tooltip("Horizontal search radius around the player (meters).")]
|
|
[SerializeField] private float maxSearchRadius = 80f;
|
|
|
|
private void Start()
|
|
{
|
|
if (button == null)
|
|
button = GetComponent<Button>();
|
|
if (button != null)
|
|
button.onClick.AddListener(OnPickupNearestClicked);
|
|
else
|
|
Debug.LogWarning("PickupNearestButtonHandler: No Button component found.");
|
|
}
|
|
|
|
public void OnPickupNearestClicked()
|
|
{
|
|
var host = CECGameRun.Instance?.GetHostPlayer();
|
|
if (host == null)
|
|
{
|
|
Debug.LogWarning("PickupNearestButtonHandler: Host player not found.");
|
|
return;
|
|
}
|
|
|
|
host.TryPickupNearestGroundMatter(maxSearchRadius);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (button != null)
|
|
button.onClick.RemoveListener(OnPickupNearestClicked);
|
|
}
|
|
}
|
|
}
|