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

86 lines
2.3 KiB
C#
Raw Normal View History

2018-04-21 12:22:17 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2018-04-21 15:39:48 +02:00
public class Room : MonoBehaviour {
List<Door> doors;
2018-04-21 16:13:59 +02:00
List<Transform> spawnpoints;
2018-04-21 15:39:48 +02:00
[SerializeField]
GameObject doorsRootObject;
2018-04-21 16:13:59 +02:00
[SerializeField]
GameObject spawnpointRootObject;
private Objective objective;
2018-04-22 11:27:09 +02:00
// Use this for initialization
void Start() {
2018-04-21 15:39:48 +02:00
doors = new List<Door>();
foreach ( Door d in doorsRootObject.GetComponentsInChildren<Door>() ) {
2018-04-21 15:39:48 +02:00
doors.Add(d);
}
Debug.Log("[ROOMS] Doors: " + doors.Count);
2018-04-21 16:13:59 +02:00
spawnpoints = new List<Transform>();
foreach ( Transform t in spawnpointRootObject.GetComponentsInChildren<Transform>() ) {
if ( t.gameObject != spawnpointRootObject ) {
spawnpoints.Add(t);
}
2018-04-21 16:13:59 +02:00
}
Debug.Log("[ROOMS] Spawnpoints: " + spawnpoints.Count);
}
2018-04-21 15:39:48 +02:00
/// <summary>
/// Locks all doors associated with this room.
/// </summary>
public void Lock() {
foreach ( Door d in doors ) {
2018-04-21 15:39:48 +02:00
d.Lock();
}
Debug.Log("[ROOMS] Locked all doors...");
2018-04-21 15:39:48 +02:00
}
/// <summary>
/// Unlocks all doors associated with this room.
/// </summary>
public void Unlock() {
foreach ( Door d in doors ) {
2018-04-21 15:39:48 +02:00
d.Unlock();
}
Debug.Log("[ROOMS] Unlocked all doors...");
2018-04-21 15:39:48 +02:00
}
/// <summary>
/// Sets the rooms Objective.
/// </summary>
/// <param name="obj">Objective</param>
public void SetObjective(Objective obj) {
objective = obj;
}
/// <summary>
/// Informs the objective / activates it and ensures that a cleared room is not going to be activated again.
/// </summary>
/// <param name="player"></param>
public void OnPlayerEnter(Player player) {
if ( objective != null && objective.GetFinished() ) {
Debug.Log("[ROOMS] This room has been cleared already.");
2018-04-22 11:27:09 +02:00
return;
}
if ( objective != null ) {
Debug.Log("[ROOMS] Player activated Objective");
objective.ActivateGoal(player);
}
}
/// <summary>
/// Returns the Spawnpoints a room has.
/// </summary>
/// <returns></returns>
public List<Transform> GetSpawnpoints() {
2018-04-21 16:13:59 +02:00
return spawnpoints;
}
2018-04-21 12:22:17 +02:00
}