(Feat) Bed Systeme
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
using UnityEngine;
|
||||
using Ashwild.Interaction;
|
||||
using Ashwild.Player;
|
||||
|
||||
namespace Ashwild.Building
|
||||
{
|
||||
/// <summary>
|
||||
/// A placed bed the local player interacts with to make it their respawn point (Valheim-style
|
||||
/// claim). Interacting pushes the bed's pose onto the bus, where the local PlayerLifecycle adopts
|
||||
/// it — so the respawn point is per-player and never networked: one bed at the base can serve as
|
||||
/// everyone's spawn, yet each teammate only rebinds their own by interacting, and a bed placed
|
||||
/// far away changes nobody else's. The bed itself is an ordinary built structure (instantiated
|
||||
/// locally on every client from the BuildRegistry), never a NetworkObject — so there is nothing
|
||||
/// to add on the build side: dropping this component on a buildable's BuiltPrefab is enough.
|
||||
/// </summary>
|
||||
[DisallowMultipleComponent]
|
||||
[RequireComponent(typeof(Collider))]
|
||||
public class Bed : MonoBehaviour, IInteractable
|
||||
{
|
||||
#region Serialized Fields
|
||||
|
||||
[Header("Respawn")]
|
||||
[Tooltip("Where the player reappears when respawning here — a child placed beside the bed, facing away from it. Falls back to the bed's own transform when left empty.")]
|
||||
[SerializeField] private Transform respawnAnchor;
|
||||
|
||||
[Tooltip("Label shown under the crosshair while aiming at the bed.")]
|
||||
[SerializeField] private string interactionPrompt = "Définir le point de réveil";
|
||||
|
||||
#endregion
|
||||
|
||||
#region IInteractable
|
||||
|
||||
/// <summary>
|
||||
/// Label shown under the crosshair while aiming at the bed.
|
||||
/// </summary>
|
||||
public string InteractionPrompt => interactionPrompt;
|
||||
|
||||
/// <summary>
|
||||
/// Claims this bed as the local player's respawn point by broadcasting its pose over the bus.
|
||||
/// Called by PlayerInteractor on the interacting client only (it is owner-gated), so only that
|
||||
/// player rebinds — teammates are untouched.
|
||||
/// </summary>
|
||||
public void Interact()
|
||||
{
|
||||
Transform anchor = respawnAnchor != null ? respawnAnchor : transform;
|
||||
PlayerEvents.RaiseRespawnPointChanged(anchor.position, anchor.rotation);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user