68 lines
1.8 KiB
C#
68 lines
1.8 KiB
C#
|
|
using UnityEngine;
|
||
|
|
using System.Collections;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Example interactive object: A bridge that the player can cross.
|
||
|
|
/// Can be destroyed, collapsed, or require conditions to cross safely.
|
||
|
|
/// </summary>
|
||
|
|
public class Bridge : MonoBehaviour, IInteractiveObject
|
||
|
|
{
|
||
|
|
[Header("Bridge Settings")]
|
||
|
|
public string bridgeName = "Bridge";
|
||
|
|
public bool isPassable = true;
|
||
|
|
[SerializeField]
|
||
|
|
private float crossingDuration = 3f; // Time to cross the bridge
|
||
|
|
|
||
|
|
[Header("Interaction Point")]
|
||
|
|
public Transform interactionPoint; // Where player should stand to interact
|
||
|
|
|
||
|
|
private Coroutine crossingRoutine;
|
||
|
|
|
||
|
|
public Vector3 GetInteractionPoint()
|
||
|
|
{
|
||
|
|
if (interactionPoint != null)
|
||
|
|
return interactionPoint.position;
|
||
|
|
return transform.position;
|
||
|
|
}
|
||
|
|
|
||
|
|
public bool CanInteract()
|
||
|
|
{
|
||
|
|
return isPassable;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void Interact(GameObject player)
|
||
|
|
{
|
||
|
|
if (!isPassable)
|
||
|
|
{
|
||
|
|
Debug.Log("Bridge is not passable!", gameObject);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
Debug.Log($"Player {player.name} is crossing {bridgeName}", gameObject);
|
||
|
|
|
||
|
|
// You can add animation, effects, or checks here
|
||
|
|
// For example: play crossing animation, check integrity, trigger events, etc.
|
||
|
|
}
|
||
|
|
|
||
|
|
public string GetDisplayName() => bridgeName;
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Make the bridge impassable (destroyed, collapsed, etc.)
|
||
|
|
/// </summary>
|
||
|
|
public void Collapse()
|
||
|
|
{
|
||
|
|
isPassable = false;
|
||
|
|
Debug.Log($"{bridgeName} has collapsed!", gameObject);
|
||
|
|
// Add visual effects, sounds, animations here
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// Repair the bridge
|
||
|
|
/// </summary>
|
||
|
|
public void Repair()
|
||
|
|
{
|
||
|
|
isPassable = true;
|
||
|
|
Debug.Log($"{bridgeName} has been repaired!", gameObject);
|
||
|
|
}
|
||
|
|
}
|