Couple PlayerUpgrade with Player
This commit is contained in:
parent
52a7a536c8
commit
712965e5ad
6 changed files with 16 additions and 19 deletions
|
@ -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)
|
||||
|
|
|
@ -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<PlayerController>();
|
||||
PerformUpgrade();
|
||||
_upgradeManager.ClaimUpgrade(gameObject);
|
||||
Destroy(gameObject);
|
||||
|
|
|
@ -37,7 +37,6 @@ namespace src.Managers
|
|||
_gameStateManager = gameObject.AddComponent<GameStateManager>();
|
||||
_levelManager = gameObject.AddComponent<LevelManager>();
|
||||
_upgradeManager = gameObject.AddComponent<UpgradeManager>();
|
||||
gameObject.AddComponent<PlayerUpgrade>();
|
||||
|
||||
// Load external components
|
||||
_playerController = GameObject.Find("Player").GetComponent<PlayerController>();
|
||||
|
|
|
@ -31,10 +31,14 @@ namespace src.Player
|
|||
private static readonly int AnimDeath = Animator.StringToHash("AnimDeath");
|
||||
|
||||
|
||||
protected void Awake()
|
||||
{
|
||||
_playerUpgrade = gameObject.AddComponent<PlayerUpgrade>();
|
||||
}
|
||||
|
||||
protected void Start()
|
||||
{
|
||||
_gameStateManager = GameStateManager.instance;
|
||||
_playerUpgrade = PlayerUpgrade.instance;
|
||||
_bombsUtil = BombsUtilManager.instance;
|
||||
|
||||
_rigidbody2d = GetComponent<Rigidbody2D>();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -7,7 +7,7 @@ namespace src.Upgrade
|
|||
{
|
||||
public override void PerformUpgrade()
|
||||
{
|
||||
var player = PlayerUpgrade.instance;
|
||||
var player = _playerToUpgrade.GetComponent<PlayerUpgrade>();
|
||||
player.IncreaseSpeed(.5f);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue