Files
Click-PointRPG/Assets/Scripts/Ledge.cs

92 lines
2.7 KiB
C#

using UnityEngine;
/// <summary>
/// Example interactive object: A ledge that the player can jump over.
/// Can have conditions like requiring a minimum jump height or specific equipment.
/// </summary>
public class Ledge : InteractiveObjectBase
{
[Header("Ledge Settings")]
public string ledgeName = "Ledge";
public float height = 2f; // Height of the ledge
[SerializeField]
private float requiredJumpPower = 1f; // 0-1 scale, 1 being maximum jump
[Header("Traversal")]
public Transform jumpStartPoint; // Where player should stand to jump
public Transform jumpEndPoint; // Where player lands after jumping
public bool isTraversable = true;
/// <summary>
/// Check if the player can safely jump this ledge
/// (Implement with player stats, equipment, etc.)
/// </summary>
public bool CanPlayerJump(Character player)
{
// Add custom logic here
// Example: check if player has enough stamina, equipment bonuses, etc.
return true;
}
public override bool CanInteract()
{
return isTraversable;
}
public override void Interact(GameObject player)
{
if (!isTraversable)
{
Log("Cannot jump over this ledge!");
return;
}
Log($"Player {player.name} is jumping over {ledgeName}");
// You can trigger jump animation, apply force, teleport player, etc.
// Example: Move player to the end point
if (jumpEndPoint != null)
{
var movement = player.GetComponent<NavMeshMovementController>();
if (movement != null)
{
movement.MoveTo(jumpEndPoint.position);
}
else
{
player.transform.position = jumpEndPoint.position;
}
}
}
public override Vector3 GetInteractionPoint()
{
if (jumpStartPoint != null)
return jumpStartPoint.position;
return base.GetInteractionPoint();
}
public override string GetDisplayName() => $"{ledgeName} (Height: {height}m)";
/// <summary>
/// Block the ledge (might be destroyed, blocked by debris, etc.)
/// </summary>
public void Block()
{
isTraversable = false;
Log($"{ledgeName} is now blocked!");
}
void OnDrawGizmos()
{
// Visual debugging
if (jumpStartPoint != null && jumpEndPoint != null)
{
Gizmos.color = Color.green;
Gizmos.DrawLine(jumpStartPoint.position, jumpEndPoint.position);
Gizmos.DrawWireSphere(jumpStartPoint.position, 0.2f);
Gizmos.DrawWireSphere(jumpEndPoint.position, 0.2f);
}
}
}