diff options
author | Neil Kollack <nkollack@gmail.com> | 2022-04-16 16:33:55 -0500 |
---|---|---|
committer | Neil Kollack <nkollack@gmail.com> | 2022-04-16 16:33:55 -0500 |
commit | 5339e773f247bdf81fa3b30a4a03c748732b5046 (patch) | |
tree | dc733314de0dc1d261db2531c739788b167635b1 /Assets/Scripts | |
parent | 92690dd53e3bfc05bbd8b7338f6e57961eb08b93 (diff) |
fix: feedback(easier trap section + better damage)
Diffstat (limited to 'Assets/Scripts')
-rw-r--r-- | Assets/Scripts/Actors/Actor.cs | 30 | ||||
-rw-r--r-- | Assets/Scripts/LevelController.cs | 46 |
2 files changed, 63 insertions, 13 deletions
diff --git a/Assets/Scripts/Actors/Actor.cs b/Assets/Scripts/Actors/Actor.cs index 9a4b338..6b82060 100644 --- a/Assets/Scripts/Actors/Actor.cs +++ b/Assets/Scripts/Actors/Actor.cs @@ -15,6 +15,7 @@ namespace MontanaJohns.Actors [SerializeField] protected float gravityScale = 1.5f; [SerializeField] protected Stats baseStats = Stats.DefaultBaseStats(); [SerializeField] protected Transform groundCheckPoint; + [SerializeField] protected float invulnTime = 0f; protected Rigidbody2D _rigidBody; protected SpriteRenderer _renderer; @@ -32,6 +33,8 @@ namespace MontanaJohns.Actors public Stats stats; public int health; + public bool invuln; + protected virtual void Awake() { _rigidBody = GetComponent<Rigidbody2D>(); @@ -39,10 +42,7 @@ namespace MontanaJohns.Actors _renderer = GetComponent<SpriteRenderer>(); _animator = GetComponent<Animator>(); groundLayers = LayerMask.GetMask("Grapple", "Ground"); - } - protected virtual void Start() - { _rigidBody.freezeRotation = true; _rigidBody.collisionDetectionMode = CollisionDetectionMode2D.Continuous; _rigidBody.gravityScale = gravityScale; @@ -53,6 +53,11 @@ namespace MontanaJohns.Actors jumpCount = stats.maxJumps; } + protected virtual void Start() + { + + } + protected virtual void FixedUpdate() { if (!_animator.GetBool("airborn") && !Physics2D.OverlapCircle(groundCheckPoint.position, 0.2f, groundLayers)) @@ -137,18 +142,29 @@ namespace MontanaJohns.Actors public virtual void TakeDamage(int damage) { - health -= damage; - StartCoroutine(DamageAnimation()); + StartCoroutine(Damage(damage)); + } + + private IEnumerator Damage(int damage) + { + if(!invuln) + { + invuln = true; + health -= damage; + StartCoroutine(DamageAnimation()); + yield return new WaitForSeconds(invulnTime); + invuln = false; + } } - IEnumerator DamageAnimation() + private IEnumerator DamageAnimation() { _renderer.color = Color.red; yield return new WaitForSeconds(0.5f); _renderer.color = Color.white; } - IEnumerator Falling() + private IEnumerator Falling() { _animator.SetBool("airborn", true); diff --git a/Assets/Scripts/LevelController.cs b/Assets/Scripts/LevelController.cs index 7c7355e..1b8bd47 100644 --- a/Assets/Scripts/LevelController.cs +++ b/Assets/Scripts/LevelController.cs @@ -1,12 +1,15 @@ using System.Collections; using System.Collections.Generic; +using UnityEditor; using UnityEngine; using UnityEngine.SceneManagement; public class LevelController : MonoBehaviour { [SerializeField] GameObject treasure; - // Start is called before the first frame update + [SerializeField] List<GameObject> enemies; + + private string clone = "(Clone)"; public void StartGame() { @@ -15,13 +18,44 @@ public class LevelController : MonoBehaviour public void ResetLevel() { + //Destroy Destroy(GameObject.Find("Boulder(Clone)")); Destroy(GameObject.Find("BoobyTrapSpawnPoint(Clone)")); - var currentTreasure = GameObject.Find("Treasure"); - if(currentTreasure) - Destroy(currentTreasure); - else - Destroy(GameObject.Find("Treasure(Clone)")); + CloneDestroy("Treasure"); + DestroyList(enemies); + + //Instantiate Instantiate(treasure); + InstantiateList(enemies); + } + + private void CloneDestroy(string objectName) + { + var obj = GameObject.Find(objectName); + if (obj) + Destroy(obj); + else + { + obj = GameObject.Find(objectName + clone); + if (obj) + Destroy(GameObject.Find(objectName + clone)); + } + } + + private void DestroyList(List<GameObject> gameObjects) + { + foreach(GameObject obj in gameObjects) + { + CloneDestroy(obj.name); + } + } + + private void InstantiateList(List<GameObject> gameObjects) + { + foreach (GameObject obj in gameObjects) + { + PrefabUtility.RevertPrefabInstance(obj, InteractionMode.AutomatedAction); + Instantiate(obj); + } } } |