2018-04-21 15:39:48 +02:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class Door : MonoBehaviour {
|
|
|
|
|
private bool locked = false;
|
2018-04-21 16:24:58 +02:00
|
|
|
|
|
2018-04-22 05:57:26 +02:00
|
|
|
|
[SerializeField]
|
|
|
|
|
GameObject graphics;
|
|
|
|
|
|
2018-04-22 11:27:09 +02:00
|
|
|
|
[SerializeField]
|
|
|
|
|
Room parent;
|
|
|
|
|
|
2018-04-21 16:24:58 +02:00
|
|
|
|
BoxCollider2D boundingBox;
|
2018-04-21 18:21:31 +02:00
|
|
|
|
BoxCollider2D triggerBox;
|
2018-04-21 15:39:48 +02:00
|
|
|
|
// Use this for initialization
|
|
|
|
|
void Start () {
|
2018-04-21 18:21:31 +02:00
|
|
|
|
BoxCollider2D[] colliders = GetComponents<BoxCollider2D>();
|
|
|
|
|
foreach (BoxCollider2D collider in colliders) {
|
|
|
|
|
if (collider.isTrigger) {
|
|
|
|
|
triggerBox = collider;
|
2018-04-22 05:57:26 +02:00
|
|
|
|
Debug.Log("Found Door trigger");
|
2018-04-21 18:21:31 +02:00
|
|
|
|
} else {
|
|
|
|
|
boundingBox = collider;
|
2018-04-22 05:57:26 +02:00
|
|
|
|
Debug.Log("Found Door collider");
|
2018-04-21 18:21:31 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-21 16:24:58 +02:00
|
|
|
|
Unlock();
|
2018-04-21 15:39:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Lock()
|
|
|
|
|
{
|
|
|
|
|
locked = true;
|
2018-04-21 16:24:58 +02:00
|
|
|
|
boundingBox.enabled = true;
|
2018-04-21 18:21:31 +02:00
|
|
|
|
triggerBox.enabled = false;
|
2018-04-22 05:57:26 +02:00
|
|
|
|
graphics.GetComponent<SpriteRenderer>().enabled = true;
|
2018-04-21 15:39:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Unlock()
|
|
|
|
|
{
|
|
|
|
|
locked = false;
|
2018-04-21 16:24:58 +02:00
|
|
|
|
boundingBox.enabled = false;
|
2018-04-21 18:21:31 +02:00
|
|
|
|
triggerBox.enabled = true;
|
2018-04-22 05:57:26 +02:00
|
|
|
|
graphics.GetComponent<SpriteRenderer>().enabled = false;
|
2018-04-21 15:39:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsLocked()
|
|
|
|
|
{
|
|
|
|
|
return locked;
|
|
|
|
|
}
|
2018-04-22 11:27:09 +02:00
|
|
|
|
|
|
|
|
|
private void OnTriggerExit2D(Collider2D collision)
|
|
|
|
|
{
|
|
|
|
|
if (collision.tag == "Player")
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("Leavin Trigger");
|
|
|
|
|
parent.OnPlayerEnter();
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-21 15:39:48 +02:00
|
|
|
|
}
|