1
0
Fork 0
Bildschirmflausch-LD41/Assets/Scripts/Door.cs

49 lines
1.1 KiB
C#
Raw Normal View History

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;
[SerializeField]
GameObject graphics;
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;
Debug.Log("Found Door trigger");
2018-04-21 18:21:31 +02:00
} else {
boundingBox = collider;
Debug.Log("Found Door collider");
2018-04-21 18:21:31 +02:00
}
}
Unlock();
2018-04-21 15:39:48 +02:00
}
public void Lock()
{
locked = true;
boundingBox.enabled = true;
2018-04-21 18:21:31 +02:00
triggerBox.enabled = false;
graphics.GetComponent<SpriteRenderer>().enabled = true;
2018-04-21 15:39:48 +02:00
}
public void Unlock()
{
locked = false;
boundingBox.enabled = false;
2018-04-21 18:21:31 +02:00
triggerBox.enabled = true;
graphics.GetComponent<SpriteRenderer>().enabled = false;
2018-04-21 15:39:48 +02:00
}
public bool IsLocked()
{
return locked;
}
}