diff --git a/Assets/Scripts/src/Base/EnemyBase.cs b/Assets/Scripts/src/Base/EnemyBase.cs index 4db57b5..eede5d5 100644 --- a/Assets/Scripts/src/Base/EnemyBase.cs +++ b/Assets/Scripts/src/Base/EnemyBase.cs @@ -65,7 +65,7 @@ namespace src.Base Collider2D.enabled = false; _isDead = true; Animator.SetTrigger(AnimExplode); - Destroy(gameObject, 1); + Destroy(gameObject, 0.7f); } public void OnCollisionEnter2D(Collision2D col) diff --git a/Assets/Scripts/src/Base/UpgradeBase.cs b/Assets/Scripts/src/Base/UpgradeBase.cs index 75f74c2..3bb7281 100644 --- a/Assets/Scripts/src/Base/UpgradeBase.cs +++ b/Assets/Scripts/src/Base/UpgradeBase.cs @@ -1,5 +1,7 @@ using src.Interfaces; using src.Managers; +using src.Player; +using src.Upgrade; using UnityEngine; namespace src.Base @@ -8,6 +10,7 @@ namespace src.Base { protected GameManager gameManager; private UpgradeManager _upgradeManager; + protected PlayerController _playerToUpgrade; public void Start() { @@ -23,6 +26,7 @@ namespace src.Base public void OnTriggerEnter2D(Collider2D other) { if (!other.CompareTag("Player")) return; + _playerToUpgrade = other.GetComponent(); PerformUpgrade(); _upgradeManager.ClaimUpgrade(gameObject); Destroy(gameObject); diff --git a/Assets/Scripts/src/Managers/GameManager.cs b/Assets/Scripts/src/Managers/GameManager.cs index a925a9b..6243c7c 100644 --- a/Assets/Scripts/src/Managers/GameManager.cs +++ b/Assets/Scripts/src/Managers/GameManager.cs @@ -37,7 +37,6 @@ namespace src.Managers _gameStateManager = gameObject.AddComponent(); _levelManager = gameObject.AddComponent(); _upgradeManager = gameObject.AddComponent(); - gameObject.AddComponent(); // Load external components _playerController = GameObject.Find("Player").GetComponent(); diff --git a/Assets/Scripts/src/Player/PlayerController.cs b/Assets/Scripts/src/Player/PlayerController.cs index 83ec1fd..e1c5429 100644 --- a/Assets/Scripts/src/Player/PlayerController.cs +++ b/Assets/Scripts/src/Player/PlayerController.cs @@ -29,14 +29,18 @@ namespace src.Player private static readonly int AnimHorizontal = Animator.StringToHash("AnimHorizontal"); private static readonly int AnimVertical = Animator.StringToHash("AnimVertical"); private static readonly int AnimDeath = Animator.StringToHash("AnimDeath"); - + + + protected void Awake() + { + _playerUpgrade = gameObject.AddComponent(); + } protected void Start() { _gameStateManager = GameStateManager.instance; - _playerUpgrade = PlayerUpgrade.instance; _bombsUtil = BombsUtilManager.instance; - + _rigidbody2d = GetComponent(); _collider2D = GetComponent(); _animator = GetComponentInChildren(); diff --git a/Assets/Scripts/src/Player/PlayerUpgrade.cs b/Assets/Scripts/src/Player/PlayerUpgrade.cs index a98ae1e..290c1c4 100644 --- a/Assets/Scripts/src/Player/PlayerUpgrade.cs +++ b/Assets/Scripts/src/Player/PlayerUpgrade.cs @@ -4,24 +4,14 @@ namespace src.Player { public class PlayerUpgrade : GameplayComponent { + /* Events & Delegates */ public delegate void IncreaseSpeedDelegate(float speed); - public static PlayerUpgrade instance; public event IncreaseSpeedDelegate PlayerSpeed; + + /* Variables */ public const float MaxPlayerSpeed = 8f; private float _movementSpeed = 4f; - public void Awake() - { - if (instance == null) - { - instance = this; - } - else if (instance != null) - { - Destroy(gameObject); - } - } - public float GetMovementSpeed() { return _movementSpeed; diff --git a/Assets/Scripts/src/Upgrade/PlayerSpeedUpgrade.cs b/Assets/Scripts/src/Upgrade/PlayerSpeedUpgrade.cs index 94558e0..76fc482 100644 --- a/Assets/Scripts/src/Upgrade/PlayerSpeedUpgrade.cs +++ b/Assets/Scripts/src/Upgrade/PlayerSpeedUpgrade.cs @@ -7,7 +7,7 @@ namespace src.Upgrade { public override void PerformUpgrade() { - var player = PlayerUpgrade.instance; + var player = _playerToUpgrade.GetComponent(); player.IncreaseSpeed(.5f); } }