Files
2025-05-13 05:19:58 +03:00

63 lines
1.5 KiB
C#

using UnityEngine;
using System.Collections;
public class DoorController: MonoBehaviour {
private bool isPlayerInside;
private GameAction doorAction = new GameAction();
public Door door;
public GameObject obstacle;
public PlayerSensor sensor;
private Notification _notify;
public bool locked;
// Use this for initialization
void Start () {
doorAction.target = gameObject;
_notify = new Notification();
_notify.source = gameObject;
_notify.text = "Door locked";
if(sensor != null){
sensor.PlayerEnter += HandlePlayerEnter;
sensor.PlayerExit += HandlePlayerExit;
}
}
void HandlePlayerEnter (PlayerSensor sensor, GameObject player)
{
if (locked) {
NotificationsController.AddNotification(_notify);
}
else {
ActionController.AddAction(doorAction);
}
}
void HandlePlayerExit (PlayerSensor sensor, GameObject player)
{
NotificationsController.RemoveNotification(_notify);
ActionController.RemoveAction(doorAction);
}
// Update is called once per frame
void Update () {
obstacle.SetActive(door.State != DoorState.Opened);
if(door.State == DoorState.Closed || door.State == DoorState.Closing){
doorAction.text = "Open the door";
}else{
doorAction.text = "Close the door";
}
}
void OnAction(ActionArgs param) {
if(door.State == DoorState.Closed || door.State == DoorState.Closing){
door.Open();
}else{
door.Close();
}
//ActionController.RemoveAction(param);
}
}