charge damage and cooldown implemented
This commit is contained in:
parent
f28e57eeb7
commit
228e16b2b4
@ -36,7 +36,7 @@ AnimatorController:
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_Controller: {fileID: 0}
|
||||
m_AnimatorLayers:
|
||||
- serializedVersion: 5
|
||||
m_Name: Base Layer
|
||||
|
||||
@ -1118,11 +1118,13 @@ MonoBehaviour:
|
||||
_attack_damage: 3
|
||||
_attack_interval: 2
|
||||
_enemy: {fileID: 0}
|
||||
_chargeAttackDamage: 5
|
||||
_chargeCooldown: 5
|
||||
_maxChargeHitCount: 3
|
||||
_maxChargeDistance: 10
|
||||
_detection: {fileID: 9048754633958631738}
|
||||
_chargeDetection: {fileID: 4280547952316628076}
|
||||
_root: {fileID: 2230360378127571586}
|
||||
_maxChargeHitCount: 3
|
||||
_maxChargeDistance: 10
|
||||
--- !u!1839735485 &3032268583489863936
|
||||
Tilemap:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@ -4,23 +4,29 @@ using UnityEngine;
|
||||
|
||||
public class Rider : Ally
|
||||
{
|
||||
[SerializeField]
|
||||
private int _chargeAttackDamage;
|
||||
[SerializeField]
|
||||
private int _chargeCooldown;
|
||||
[SerializeField]
|
||||
private int _maxChargeHitCount;
|
||||
[SerializeField]
|
||||
private int _maxChargeDistance;
|
||||
[SerializeField]
|
||||
private GameObject _detection;
|
||||
[SerializeField]
|
||||
private GameObject _chargeDetection;
|
||||
private Detection _chargeDetectionScript;
|
||||
[SerializeField]
|
||||
private GameObject _root;
|
||||
|
||||
private Detection _chargeDetectionScript;
|
||||
private Root _rootScript;
|
||||
|
||||
private Vector3 _originalPos;
|
||||
private Vector2 _movementVector = Vector2.zero;
|
||||
private bool _isCharging;
|
||||
[SerializeField]
|
||||
private int _maxChargeHitCount;
|
||||
private float _timeSinceLastCharge;
|
||||
private List<Entity> _opponentsHit = new List<Entity>();
|
||||
[SerializeField]
|
||||
private int _maxChargeDistance;
|
||||
private Vector3 _originalPos;
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
@ -35,8 +41,15 @@ public class Rider : Ally
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
// check for charge cooldown
|
||||
if (_timeSinceLastCharge > _chargeCooldown)
|
||||
{
|
||||
_isCharging = true;
|
||||
}
|
||||
|
||||
if (_isCharging)
|
||||
{
|
||||
// toggle charge detection
|
||||
_detection.SetActive(false);
|
||||
_chargeDetection.SetActive(true);
|
||||
|
||||
@ -53,20 +66,27 @@ public class Rider : Ally
|
||||
// reset
|
||||
if (transform.position.x - _originalPos.x >= _maxChargeDistance || _opponentsHit.Count >= _maxChargeHitCount)
|
||||
{
|
||||
_isCharging = false;
|
||||
// position
|
||||
_movementVector = Vector2.zero;
|
||||
transform.position = _originalPos;
|
||||
|
||||
// charge state
|
||||
_isCharging = false;
|
||||
_timeSinceLastCharge = 0;
|
||||
_opponentsHit.Clear();
|
||||
|
||||
// detection state
|
||||
IsEnemyDetected = false;
|
||||
Enemy = null;
|
||||
|
||||
// toggle detection
|
||||
_detection.SetActive(true);
|
||||
_chargeDetection.SetActive(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_timeSinceLastCharge += Time.deltaTime;
|
||||
if (IsEnemyDetected)
|
||||
{
|
||||
AttackEnemy();
|
||||
@ -76,7 +96,7 @@ public class Rider : Ally
|
||||
|
||||
void AttackEnemyRiding()
|
||||
{
|
||||
_rootScript.Attack();
|
||||
_rootScript.AttackWithCustomDamage(_chargeAttackDamage);
|
||||
_opponentsHit.Add(Enemy);
|
||||
}
|
||||
|
||||
|
||||
@ -24,6 +24,18 @@ public class Root : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void AttackWithCustomDamage(int damage)
|
||||
{
|
||||
if (_entity == null || _entity.Enemy == null) return;
|
||||
|
||||
_entity.Enemy.Hit(damage);
|
||||
if (_entity.Enemy.Hp <= 0)
|
||||
{
|
||||
_entity.Enemy.Death();
|
||||
_entity.IsEnemyDetected = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void ShotProjectile()
|
||||
{
|
||||
Rigidbody2D _rigidbodyAlly;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user