Commit 264f5f48 authored by Markus Schlösser's avatar Markus Schlösser
Browse files

Added Reset on Player death

parent a1552ba1
using UnityEngine;
public class CannonController : MonoBehaviour {
public class CannonController : MonoBehaviour, IResetable {
[SerializeField] private GameObject cannonBarrel;
[SerializeField] private GameObject fire;
[SerializeField] private float shotsPerSeconds;
......@@ -30,4 +30,8 @@ public class CannonController : MonoBehaviour {
// Flugrichtung
obj.GetComponent<Rigidbody2D>().velocity = cannonBarrel.transform.right * speed;
}
public void ResetToLevelBegin() {
cooldown = 0;
}
}
public interface IResetable {
void ResetToLevelBegin();
}
fileFormatVersion: 2
guid: fc2358c72d6461d42a2caaabffa1fd09
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -2,8 +2,7 @@
using UnityEngine;
using UnityEngine.Events;
public class InteractibleLever : MonoBehaviour, IInteractible {
public class InteractibleLever : MonoBehaviour, IInteractible, IResetable {
[System.Serializable]
private class BoolEvent : UnityEvent<bool> { }
......@@ -20,8 +19,7 @@ public class InteractibleLever : MonoBehaviour, IInteractible {
private bool state;
private void Awake() {
state = isActive;
UpdateSprite();
ResetToLevelBegin();
}
public void Interact(PlayerActor source) {
......@@ -32,8 +30,14 @@ public class InteractibleLever : MonoBehaviour, IInteractible {
UpdateSprite();
}
}
private void UpdateSprite() {
render.sprite = state ? active : inactive;
}
public void ResetToLevelBegin() {
state = isActive;
UpdateSprite();
onInteract.Invoke(isActive);
}
}
using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine;
public class LaserController : MonoBehaviour {
......
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Tilemaps;
public class PlayerActor : MonoBehaviour {
public class PlayerActor : MonoBehaviour, IResetable {
private const int MAX_STEPS = 128;
private const float CONCAVE_RADIUS = 0.5f;
......@@ -395,7 +396,15 @@ public class PlayerActor : MonoBehaviour {
UpdateOrientation();
}
public void Die() {
private static void Die() {
// TODO: This call is really inefficient
IResetable[] resetables = FindObjectsOfType<MonoBehaviour>().OfType<IResetable>().ToArray();
foreach (IResetable r in resetables) {
r.ResetToLevelBegin();
}
}
public void ResetToLevelBegin() {
if (movementRoutine != null) {
StopCoroutine(movementRoutine);
movementRoutine = null;
......@@ -408,7 +417,6 @@ public class PlayerActor : MonoBehaviour {
animator.Play("Idle");
transform.position = startingPosition;
orientation = startingOrientation;
UpdateOrientation();
......
using UnityEngine;
public class ProjektilController : MonoBehaviour {
public class ProjektilController : MonoBehaviour, IResetable {
private const float MAX_LIFETIME = 15.0f;
......@@ -17,4 +17,8 @@ public class ProjektilController : MonoBehaviour {
private void OnTriggerEnter2D(Collider2D other) {
Destroy(gameObject);
}
public void ResetToLevelBegin() {
Destroy(gameObject);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine;
using UnityEngine.Events;
public class TimedToggle : MonoBehaviour {
public class TimedToggle : MonoBehaviour, IResetable {
[System.Serializable]
private class BoolEvent : UnityEvent<bool> { }
......@@ -19,7 +17,7 @@ public class TimedToggle : MonoBehaviour {
private bool state;
private void Start() {
state = isActive;
ResetToLevelBegin();
}
private void Update() {
......@@ -37,4 +35,9 @@ public class TimedToggle : MonoBehaviour {
time += Time.deltaTime;
}
public void ResetToLevelBegin() {
state = isActive;
onStateChange.Invoke(isActive);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment