92 lines
2.7 KiB
C#
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 : MonoBehaviour, IInteractiveObject
|
||
|
|
{
|
||
|
|
[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;
|
||
|
|
|
||
|
|
public Vector3 GetInteractionPoint()
|
||
|
|
{
|
||
|
|
if (jumpStartPoint != null)
|
||
|
|
return jumpStartPoint.position;
|
||
|
|
return transform.position;
|
||
|
|
}
|
||
|
|
|
||
|
|
public bool CanInteract()
|
||
|
|
{
|
||
|
|
return isTraversable;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void Interact(GameObject player)
|
||
|
|
{
|
||
|
|
if (!isTraversable)
|
||
|
|
{
|
||
|
|
Debug.Log("Cannot jump over this ledge!", gameObject);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
Debug.Log($"Player {player.name} is jumping over {ledgeName}", gameObject);
|
||
|
|
|
||
|
|
// 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 string GetDisplayName() => $"{ledgeName} (Height: {height}m)";
|
||
|
|
|
||
|
|
/// <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;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Block the ledge (might be destroyed, blocked by debris, etc.)
|
||
|
|
/// </summary>
|
||
|
|
public void Block()
|
||
|
|
{
|
||
|
|
isTraversable = false;
|
||
|
|
Debug.Log($"{ledgeName} is now blocked!", gameObject);
|
||
|
|
}
|
||
|
|
|
||
|
|
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);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|