Adds knight on horse and its animations #8
@ -67,7 +67,7 @@ AnimatorStateTransition:
|
||||
m_TransitionDuration: 0.25
|
||||
m_TransitionOffset: 0
|
||||
m_ExitTime: 0.875
|
||||
m_HasExitTime: 1
|
||||
m_HasExitTime: 0
|
||||
m_HasFixedDuration: 1
|
||||
m_InterruptionSource: 0
|
||||
m_OrderedInterruption: 1
|
||||
|
||||
@ -1235,7 +1235,7 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3062706309015911873}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalPosition: {x: 2.52, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
@ -1255,7 +1255,7 @@ BoxCollider2D:
|
||||
m_IsTrigger: 1
|
||||
m_UsedByEffector: 0
|
||||
m_UsedByComposite: 0
|
||||
m_Offset: {x: 1.7083191, y: 0}
|
||||
m_Offset: {x: -0.1805121, y: 0}
|
||||
m_SpriteTilingProperty:
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
pivot: {x: 0, y: 0}
|
||||
@ -1266,7 +1266,7 @@ BoxCollider2D:
|
||||
adaptiveTiling: 0
|
||||
m_AutoTiling: 0
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 0.5, y: 0.5}
|
||||
m_Size: {x: 0.6224893, y: 0.5}
|
||||
m_EdgeRadius: 0
|
||||
--- !u!114 &5850107427616902080
|
||||
MonoBehaviour:
|
||||
@ -2776,7 +2776,7 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 9048754633958631738}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalPosition: {x: -0.33, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
@ -2796,7 +2796,7 @@ BoxCollider2D:
|
||||
m_IsTrigger: 1
|
||||
m_UsedByEffector: 0
|
||||
m_UsedByComposite: 0
|
||||
m_Offset: {x: 1, y: 0}
|
||||
m_Offset: {x: 1.33, y: 0}
|
||||
m_SpriteTilingProperty:
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
pivot: {x: 0, y: 0}
|
||||
|
||||
@ -19,9 +19,10 @@ public class Rider : Ally
|
||||
[SerializeField]
|
||||
private GameObject _root;
|
||||
|
||||
private Detection _chargeDetectionScript;
|
||||
private Root _rootScript;
|
||||
private Detection _detectionScript;
|
||||
|
||||
private int _originalAttackDamage;
|
||||
private Vector3 _originalPos;
|
||||
private Vector2 _movementVector = Vector2.zero;
|
||||
private bool _isCharging;
|
||||
@ -32,33 +33,37 @@ public class Rider : Ally
|
||||
{
|
||||
base.Start();
|
||||
|
||||
_chargeDetectionScript = _chargeDetection.GetComponent<Detection>();
|
||||
_rootScript = _root.GetComponent<Root>();
|
||||
_detectionScript = _detection.GetComponent<Detection>();
|
||||
|
||||
_originalAttackDamage = _chargeAttackDamage;
|
||||
_originalPos = transform.position;
|
||||
_isCharging = true;
|
||||
|
||||
_timeSinceLastCharge = _chargeCooldown + 1;
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
|
||||
// check for charge cooldown
|
||||
if (_timeSinceLastCharge > _chargeCooldown)
|
||||
if (_timeSinceLastCharge > _chargeCooldown && !_isCharging)
|
||||
{
|
||||
SweepAttack();
|
||||
|
||||
_isCharging = true;
|
||||
Animation.ToggleChargeAnim(true);
|
||||
}
|
||||
|
||||
if (_isCharging)
|
||||
{
|
||||
SweepAttack();
|
||||
|
||||
// toggle charge detection
|
||||
_detection.SetActive(false);
|
||||
_chargeDetection.SetActive(true);
|
||||
|
||||
// movement
|
||||
_movementVector.x = Time.deltaTime * Speed;
|
||||
transform.position += (Vector3)_movementVector;
|
||||
|
||||
Debug.Log(IsEnemyDetected);
|
||||
// attack
|
||||
if (IsEnemyDetected && !_opponentsHit.Contains(Enemy))
|
||||
{
|
||||
@ -76,11 +81,14 @@ public class Rider : Ally
|
||||
_isCharging = false;
|
||||
_timeSinceLastCharge = 0;
|
||||
_opponentsHit.Clear();
|
||||
|
||||
|
||||
// detection state
|
||||
IsEnemyDetected = false;
|
||||
Enemy = null;
|
||||
|
||||
// toggle animation
|
||||
Animation.ToggleChargeAnim(false);
|
||||
|
||||
// toggle detection
|
||||
_detection.SetActive(true);
|
||||
_chargeDetection.SetActive(false);
|
||||
@ -96,21 +104,39 @@ public class Rider : Ally
|
||||
}
|
||||
}
|
||||
|
||||
void AttackEnemyRiding()
|
||||
// attacks all enemies already in the default detection box at start of the charge.
|
||||
// charge uses a different detection due to Enemy being the oldest opponent to enter the hitbox.
|
||||
// therefore enemies would only get hit when the previous Enemy exits, which is at the handle instead of the tip`.
|
||||
// to cover for the enemies behind the charge detection which is at the tip, we hit them all as the charge starts
|
||||
private void SweepAttack()
|
||||
{
|
||||
Debug.Log("Attack Riding");
|
||||
_rootScript.AttackWithCustomDamage(_chargeAttackDamage);
|
||||
foreach (Entity entity in _detectionScript.DetectedEntities)
|
||||
{
|
||||
Enemy = entity;
|
||||
AttackEnemyRiding();
|
||||
}
|
||||
if (_detectionScript.DetectedEntities.Count > 0)
|
||||
{
|
||||
_detection.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void AttackEnemyRiding()
|
||||
{
|
||||
AttackDamage = _chargeAttackDamage;
|
||||
_rootScript.Attack();
|
||||
_opponentsHit.Add(Enemy);
|
||||
}
|
||||
|
||||
void AttackEnemy()
|
||||
private void AttackEnemy()
|
||||
{
|
||||
//Attack Cooldown
|
||||
if (AttackSpeedWait > AttackInterval)
|
||||
{
|
||||
|
||||
AttackDamage = _originalAttackDamage;
|
||||
Animation.PlayAttackAnim();
|
||||
|
||||
|
||||
AttackSpeedWait = 0f;
|
||||
}
|
||||
|
||||
|
||||
@ -4,12 +4,13 @@ using UnityEngine;
|
||||
|
||||
public class AnimationEntity : MonoBehaviour
|
||||
{
|
||||
enum EntityAnimationState
|
||||
enum EntityAnimationState
|
||||
{
|
||||
Idle = 0,
|
||||
Walking = 1,
|
||||
Attacking = 2,
|
||||
Dying = 3
|
||||
Dying = 3,
|
||||
Charging = 4
|
||||
}
|
||||
private EntityAnimationState entityState;
|
||||
|
||||
@ -17,15 +18,15 @@ public class AnimationEntity : MonoBehaviour
|
||||
private bool _doSomething = false;
|
||||
private bool _isDead = false;
|
||||
private bool _isWalking = false;
|
||||
|
||||
void Start()
|
||||
|
||||
void Start()
|
||||
{
|
||||
AttackSpeedMultiplier = 10;
|
||||
SpeedMultiplier = 10;
|
||||
_animatorEntity = GetComponentInChildren<Animator>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
void Update()
|
||||
{
|
||||
if (!_animatorEntity) return;
|
||||
if (_doSomething && _animatorEntity.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1f)
|
||||
@ -47,18 +48,20 @@ public class AnimationEntity : MonoBehaviour
|
||||
};
|
||||
}
|
||||
|
||||
public void PlayIdleAnim()
|
||||
public void PlayIdleAnim()
|
||||
{
|
||||
if(!_isDead) {
|
||||
if (!_isDead)
|
||||
{
|
||||
_animatorEntity.speed = 1;
|
||||
_animatorEntity.Play("idle", 0, 0f);
|
||||
entityState = EntityAnimationState.Idle;
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayWalkAnim()
|
||||
public void PlayWalkAnim()
|
||||
{
|
||||
if(!_isDead) {
|
||||
if (!_isDead)
|
||||
{
|
||||
_animatorEntity.speed = SpeedMultiplier;
|
||||
_animatorEntity.Play("walk", 0, 0f);
|
||||
entityState = EntityAnimationState.Walking;
|
||||
@ -66,9 +69,10 @@ public class AnimationEntity : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayAttackAnim()
|
||||
public void PlayAttackAnim()
|
||||
{
|
||||
if(!_isDead && _animatorEntity != null) {
|
||||
if (!_isDead && _animatorEntity != null)
|
||||
{
|
||||
_animatorEntity.speed = AttackSpeedMultiplier;
|
||||
_animatorEntity.Play("attack", 0, 0f);
|
||||
entityState = EntityAnimationState.Attacking;
|
||||
@ -76,7 +80,24 @@ public class AnimationEntity : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayDieAnim()
|
||||
public void ToggleChargeAnim(bool isCharging)
|
||||
{
|
||||
if (!_isDead && _animatorEntity != null)
|
||||
{
|
||||
_animatorEntity.speed = AttackSpeedMultiplier;
|
||||
_animatorEntity.SetBool("Charging", isCharging);
|
||||
if (isCharging)
|
||||
{
|
||||
entityState = EntityAnimationState.Charging;
|
||||
}
|
||||
else
|
||||
{
|
||||
PlayIdleAnim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayDieAnim()
|
||||
{
|
||||
// Not every entity needs an animator
|
||||
if (_animatorEntity != null)
|
||||
@ -84,7 +105,7 @@ public class AnimationEntity : MonoBehaviour
|
||||
_animatorEntity.speed = 1;
|
||||
_animatorEntity.Play("die", 0, 0f);
|
||||
}
|
||||
|
||||
|
||||
entityState = EntityAnimationState.Dying;
|
||||
_doSomething = true;
|
||||
_isDead = true;
|
||||
|
||||
@ -178,4 +178,5 @@ public class Detection : MonoBehaviour
|
||||
return rect;
|
||||
}
|
||||
}
|
||||
public List<Entity> DetectedEntities { get { return detectedEntities; } }
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ public abstract class Entity : LevelObject
|
||||
private float _attack_speed_wait = 0f;
|
||||
private AnimationEntity _animation;
|
||||
private Shader _shaderGUItext;
|
||||
private Shader _shaderSpritesDefault;
|
||||
private Shader _shaderSpritesDefault;
|
||||
private SpriteRenderer[] _spriteRenderers;
|
||||
private AudioPlayerComponent _audioPlayerComponent;
|
||||
|
||||
@ -45,41 +45,41 @@ public abstract class Entity : LevelObject
|
||||
_lifeBar.gameObject.SetActive(_lifeBar.value <= 0.99f);
|
||||
}
|
||||
//Start the animation of death and the fading of the entity
|
||||
public virtual void Death()
|
||||
public virtual void Death()
|
||||
{
|
||||
_animation.PlayDieAnim();
|
||||
Invoke("Dying", 0.1f);
|
||||
}
|
||||
|
||||
//Recursive method that fade the dying entity
|
||||
private void Dying()
|
||||
private void Dying()
|
||||
{
|
||||
foreach (SpriteRenderer renderer in _spriteRenderers)
|
||||
{
|
||||
Color currentColor = renderer.color;
|
||||
currentColor.a = currentColor.a - 0.1f;
|
||||
currentColor.a = currentColor.a - 0.1f;
|
||||
renderer.color = currentColor;
|
||||
}
|
||||
|
||||
if(_spriteRenderers[0].color.a > 0f)
|
||||
if (_spriteRenderers[0].color.a > 0f)
|
||||
{
|
||||
Invoke("Dying", 0.1f);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//When hit : get damage and start a flash of light
|
||||
public void Hit(int damage)
|
||||
public void Hit(int damage)
|
||||
{
|
||||
_hp-=damage;
|
||||
_hp -= damage;
|
||||
|
||||
_lifeBar.value = _hp / (float)_maxHp;
|
||||
|
||||
_shaderGUItext = Shader.Find("GUI/Text Shader");
|
||||
_shaderGUItext = Shader.Find("GUI/Text Shader");
|
||||
_shaderSpritesDefault = Shader.Find("Sprites/Default");
|
||||
|
||||
foreach (SpriteRenderer renderer in _spriteRenderers)
|
||||
@ -90,7 +90,7 @@ public abstract class Entity : LevelObject
|
||||
}
|
||||
|
||||
//End the flash of light from the method above
|
||||
private void ReturnNormalColor()
|
||||
private void ReturnNormalColor()
|
||||
{
|
||||
foreach (SpriteRenderer renderer in _spriteRenderers)
|
||||
{
|
||||
@ -98,15 +98,15 @@ public abstract class Entity : LevelObject
|
||||
}
|
||||
}
|
||||
|
||||
public void Move()
|
||||
public void Move()
|
||||
{
|
||||
if(!_animation.IsWalking)
|
||||
if (!_animation.IsWalking)
|
||||
{
|
||||
_animation.PlayWalkAnim();
|
||||
}
|
||||
}
|
||||
|
||||
public void PlaySound(string soundName, float volumeMultiplier = 1f, float overrideVolume = -1f)
|
||||
public void PlaySound(string soundName, float volumeMultiplier = 1f, float overrideVolume = -1f)
|
||||
{
|
||||
_audioPlayerComponent.PlaySound(soundName, volumeMultiplier, overrideVolume);
|
||||
}
|
||||
@ -123,7 +123,11 @@ public abstract class Entity : LevelObject
|
||||
|
||||
public float Speed => _speed * SpeedMultiplier;
|
||||
|
||||
public int AttackDamage => (int)(_attack_damage * DamageMultiplier);
|
||||
public int AttackDamage
|
||||
{
|
||||
get { return (int)(_attack_damage * DamageMultiplier); }
|
||||
set { _attack_damage = value; }
|
||||
}
|
||||
|
||||
public float AttackInterval => _attack_interval / AttackSpeedMultiplier;
|
||||
|
||||
|
||||
@ -24,18 +24,6 @@ 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