1
0
Fork 0

Player spawns in the right room

This commit is contained in:
Saibotk 2018-04-23 02:23:06 +02:00
parent 7914198bcb
commit ae2395e614
6 changed files with 17 additions and 8 deletions

View file

@ -10,7 +10,7 @@ public class Door : MonoBehaviour {
BoxCollider2D triggerBox;
// Use this for initialization
void Start() {
void Awake() {
BoxCollider2D[] colliders = GetComponents<BoxCollider2D>();
foreach ( BoxCollider2D collider in colliders ) {
if ( collider.isTrigger ) {
@ -21,7 +21,6 @@ public class Door : MonoBehaviour {
//Debug.Log("Found Door collider");
}
}
Unlock();
}
/// <summary>

View file

@ -176,7 +176,7 @@ public class GameController : MonoBehaviour {
spawnpointRoot.transform.position = new Vector3(dg.start.roomPosition.x, dg.start.roomPosition.y, 0);
GameObject spawn = new GameObject();
spawn.transform.SetParent(spawnpointRoot.transform);
spawn.transform.position = new Vector3(3, 3, 0);
spawn.transform.position = new Vector3(dg.start.GetCenter().x, dg.start.GetCenter().y, 0);
start.SetSpawnPointsRootObject(spawnpointRoot);
start.Reload();

View file

@ -24,6 +24,9 @@ public class EntityObjective : Objective {
/// </summary>
/// <param name="ply">Player</param>
public override void ActivateGoal(Player ply) {
if ( activated )
return;
activated = true;
base.ActivateGoal(ply);
foreach ( GameObject i in prefabList ) {
Debug.Log("[ROOMS] Spawning Entity...");

View file

@ -1,8 +1,10 @@
public abstract class Objective {
using UnityEngine;
public abstract class Objective {
protected Room room;
protected Player player;
bool activated;
bool finished;
protected bool activated;
protected bool finished;
/// <summary>
/// Constructs a new Objective instance.
@ -34,6 +36,7 @@
protected virtual void ReachedGoal() {
finished = true;
room.Unlock();
Debug.Log("[ROOM] Goal reached. Doors will open.");
}
/// <summary>

View file

@ -20,11 +20,14 @@ public class StartObjective : Objective {
/// </summary>
/// <param name="ply">Player is ignored </param>
public override void ActivateGoal(Player player) {
if ( activated )
return;
if ( room.GetSpawnpoints().Count > 0 ) {
GameObject ply = GameObject.Instantiate(playerPrefab);
ply.transform.position = room.GetSpawnpoints()[0].position;
player = ply.GetComponent<Player>();
base.ActivateGoal(player);
UpdateGoal();
}
}

View file

@ -20,7 +20,7 @@ public class Room : MonoBehaviour {
private Objective objective;
// Use this for initialization
void Start() {
void Awake() {
doors = new List<Door>();
if ( doorsRootObject != null ) {
foreach ( Door d in doorsRootObject.GetComponentsInChildren<Door>() ) {
@ -38,7 +38,7 @@ public class Room : MonoBehaviour {
}
//Debug.Log("[ROOMS] Spawnpoints: " + spawnpoints.Count);
}
//Unlock();
Unlock();
}
/// <summary>
@ -62,6 +62,7 @@ public class Room : MonoBehaviour {
}
//Debug.Log("[ROOMS] Spawnpoints: " + spawnpoints.Count);
}
Unlock(); // Ok to do so?
}
/// <summary>