charging implemented
This commit is contained in:
parent
23ecdd6ab4
commit
f28e57eeb7
@ -939,7 +939,7 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: c0fbd934c179894458914437255781c4, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
_entity: {fileID: 0}
|
||||
_entity: {fileID: 6519347188559722835}
|
||||
_projectile: {fileID: 0}
|
||||
_projectileSpawn: {fileID: 0}
|
||||
--- !u!1 &2230360378224361585
|
||||
@ -1095,6 +1095,7 @@ Transform:
|
||||
- {fileID: 2230360378000122420}
|
||||
- {fileID: 2230360378127571587}
|
||||
- {fileID: 9128510391006626171}
|
||||
- {fileID: 4282222811149129398}
|
||||
- {fileID: 7758425403302365699}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 0
|
||||
@ -1113,12 +1114,15 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier:
|
||||
_lifeBar: {fileID: 5807970101048976302}
|
||||
_hp: 30
|
||||
_speed: 1
|
||||
_speed: 2
|
||||
_attack_damage: 3
|
||||
_attack_interval: 2
|
||||
_enemy: {fileID: 0}
|
||||
_maxChargeHitCount: 2
|
||||
_maxChargeDistance: 5
|
||||
_detection: {fileID: 9048754633958631738}
|
||||
_chargeDetection: {fileID: 4280547952316628076}
|
||||
_root: {fileID: 2230360378127571586}
|
||||
_maxChargeHitCount: 3
|
||||
_maxChargeDistance: 10
|
||||
--- !u!1839735485 &3032268583489863936
|
||||
Tilemap:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -1314,6 +1318,78 @@ AudioSource:
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
--- !u!1 &4280547952316628076
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 4282222811149129398}
|
||||
- component: {fileID: 7206814474656499620}
|
||||
- component: {fileID: 262912998092095710}
|
||||
m_Layer: 6
|
||||
m_Name: detection_charge
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &4282222811149129398
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 4280547952316628076}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 2230360378425099703}
|
||||
m_RootOrder: 3
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!61 &7206814474656499620
|
||||
BoxCollider2D:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 4280547952316628076}
|
||||
m_Enabled: 1
|
||||
m_Density: 1
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 1
|
||||
m_UsedByEffector: 0
|
||||
m_UsedByComposite: 0
|
||||
m_Offset: {x: 1.7450686, y: 0}
|
||||
m_SpriteTilingProperty:
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
pivot: {x: 0, y: 0}
|
||||
oldSize: {x: 0, y: 0}
|
||||
newSize: {x: 0, y: 0}
|
||||
adaptiveTilingThreshold: 0
|
||||
drawMode: 0
|
||||
adaptiveTiling: 0
|
||||
m_AutoTiling: 0
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 0.509863, y: 0.5}
|
||||
m_EdgeRadius: 0
|
||||
--- !u!114 &262912998092095710
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 4280547952316628076}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 531d7966d86bd0c4d83baf58bcb56cd5, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
_entityLinked: {fileID: 6519347188559722835}
|
||||
--- !u!1 &4877457871086946352
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -1430,7 +1506,7 @@ Transform:
|
||||
m_Children:
|
||||
- {fileID: 430301385815424918}
|
||||
m_Father: {fileID: 2230360378425099703}
|
||||
m_RootOrder: 3
|
||||
m_RootOrder: 4
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &5807970101048976302
|
||||
MonoBehaviour:
|
||||
@ -1520,7 +1596,7 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 531d7966d86bd0c4d83baf58bcb56cd5, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
_entityLinked: {fileID: 0}
|
||||
_entityLinked: {fileID: 6519347188559722835}
|
||||
--- !u!1 &9102431410695186542
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@ -4,37 +4,65 @@ using UnityEngine;
|
||||
|
||||
public class Rider : Ally
|
||||
{
|
||||
[SerializeField]
|
||||
private GameObject _detection;
|
||||
[SerializeField]
|
||||
private GameObject _chargeDetection;
|
||||
private Detection _chargeDetectionScript;
|
||||
[SerializeField]
|
||||
private GameObject _root;
|
||||
private Root _rootScript;
|
||||
|
||||
private Vector2 _movementVector = Vector2.zero;
|
||||
private bool _isCharging;
|
||||
[SerializeField]
|
||||
private int _maxChargeHitCount;
|
||||
private List<Entity> _opponentsHit = new List<Entity>();
|
||||
[SerializeField]
|
||||
private int _maxChargeDistance;
|
||||
private int _opponentsHit;
|
||||
private float _originalPosX;
|
||||
private float _originalPosY;
|
||||
private bool _isCharging;
|
||||
|
||||
private Vector3 _originalPos;
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
base.Start();
|
||||
|
||||
_originalPosX = transform.position.x;
|
||||
_originalPosY = transform.position.y;
|
||||
_chargeDetectionScript = _chargeDetection.GetComponent<Detection>();
|
||||
_rootScript = _root.GetComponent<Root>();
|
||||
|
||||
_originalPos = transform.position;
|
||||
_isCharging = true;
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (_isCharging)
|
||||
{
|
||||
_detection.SetActive(false);
|
||||
_chargeDetection.SetActive(true);
|
||||
|
||||
// movement
|
||||
_movementVector.x = Time.deltaTime * Speed;
|
||||
transform.position += (Vector3)_movementVector;
|
||||
if (true)
|
||||
{
|
||||
|
||||
// attack
|
||||
if (IsEnemyDetected && !_opponentsHit.Contains(Enemy))
|
||||
{
|
||||
AttackEnemyRiding();
|
||||
}
|
||||
|
||||
// reset
|
||||
if (transform.position.x - _originalPos.x >= _maxChargeDistance || _opponentsHit.Count >= _maxChargeHitCount)
|
||||
{
|
||||
_isCharging = false;
|
||||
_movementVector = Vector2.zero;
|
||||
transform.position = _originalPos;
|
||||
_opponentsHit.Clear();
|
||||
|
||||
IsEnemyDetected = false;
|
||||
Enemy = null;
|
||||
|
||||
_detection.SetActive(true);
|
||||
_chargeDetection.SetActive(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -48,16 +76,8 @@ public class Rider : Ally
|
||||
|
||||
void AttackEnemyRiding()
|
||||
{
|
||||
//Attack Cooldown
|
||||
if (AttackSpeedWait > AttackInterval)
|
||||
{
|
||||
|
||||
Animation.PlayAttackAnim();
|
||||
|
||||
AttackSpeedWait = 0f;
|
||||
}
|
||||
|
||||
AttackSpeedWait += Time.deltaTime;
|
||||
_rootScript.Attack();
|
||||
_opponentsHit.Add(Enemy);
|
||||
}
|
||||
|
||||
void AttackEnemy()
|
||||
|
||||
@ -15,12 +15,27 @@ public class Detection : MonoBehaviour
|
||||
// If it's a projectile damage > 0
|
||||
private int _projectileDamage = 0;
|
||||
|
||||
private bool _hasStartBeenCalled = false;
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
_collider = GetComponent<BoxCollider2D>();
|
||||
detectionRange = _collider.size;
|
||||
|
||||
StartCoroutine(C_DetectCoroutine());
|
||||
|
||||
_hasStartBeenCalled = true;
|
||||
}
|
||||
|
||||
// Checks if Start ran once already.
|
||||
// onEnable runs by default before Start so not everything is initialized.
|
||||
// And I don't want to reinitialize the collider everytime I re-enable a unit's detection.
|
||||
protected void OnEnable()
|
||||
{
|
||||
if (_hasStartBeenCalled)
|
||||
{
|
||||
StartCoroutine(C_DetectCoroutine());
|
||||
}
|
||||
}
|
||||
|
||||
// Looped detection every 'delay' amount
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user