diff --git a/Assets/Animations/MonsterBaseAnimator.controller b/Assets/Animations/MonsterBaseAnimator.controller index d32d307..62f2cc8 100644 --- a/Assets/Animations/MonsterBaseAnimator.controller +++ b/Assets/Animations/MonsterBaseAnimator.controller @@ -1,5 +1,31 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: +--- !u!1102 &-5723871321714695223 +AnimatorState: + serializedVersion: 6 + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: New State + m_Speed: 1 + m_CycleOffset: 0 + m_Transitions: [] + m_StateMachineBehaviours: [] + m_Position: {x: 50, y: 50, z: 0} + m_IKOnFeet: 0 + m_WriteDefaultValues: 1 + m_Mirror: 0 + m_SpeedParameterActive: 0 + m_MirrorParameterActive: 0 + m_CycleOffsetParameterActive: 0 + m_TimeParameterActive: 0 + m_Motion: {fileID: 0} + m_Tag: + m_SpeedParameter: + m_MirrorParameter: + m_CycleOffsetParameter: + m_TimeParameter: --- !u!1102 &-5615459309368676638 AnimatorState: serializedVersion: 6 @@ -10,7 +36,8 @@ AnimatorState: m_Name: walk m_Speed: 1 m_CycleOffset: 0 - m_Transitions: [] + m_Transitions: + - {fileID: 6351061945338306534} m_StateMachineBehaviours: [] m_Position: {x: 50, y: 50, z: 0} m_IKOnFeet: 0 @@ -84,7 +111,8 @@ AnimatorState: m_Name: idle m_Speed: 1 m_CycleOffset: 0 - m_Transitions: [] + m_Transitions: + - {fileID: 1272373060093443428} m_StateMachineBehaviours: [] m_Position: {x: 50, y: 50, z: 0} m_IKOnFeet: 0 @@ -126,6 +154,28 @@ AnimatorState: m_MirrorParameter: m_CycleOffsetParameter: m_TimeParameter: +--- !u!1101 &1272373060093443428 +AnimatorStateTransition: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_Conditions: [] + m_DstStateMachine: {fileID: 0} + m_DstState: {fileID: 703164551053012985} + m_Solo: 0 + m_Mute: 0 + m_IsExit: 0 + serializedVersion: 3 + m_TransitionDuration: 0.25 + m_TransitionOffset: 0 + m_ExitTime: 0.75 + m_HasExitTime: 1 + m_HasFixedDuration: 1 + m_InterruptionSource: 0 + m_OrderedInterruption: 1 + m_CanTransitionToSelf: 1 --- !u!1107 &4042451101728204287 AnimatorStateMachine: serializedVersion: 6 @@ -137,16 +187,19 @@ AnimatorStateMachine: m_ChildStates: - serializedVersion: 1 m_State: {fileID: 703164551053012985} - m_Position: {x: 260, y: 110, z: 0} + m_Position: {x: 560, y: 160, z: 0} - serializedVersion: 1 m_State: {fileID: 1028912623824696338} - m_Position: {x: 260, y: 50, z: 0} + m_Position: {x: 260, y: 100, z: 0} - serializedVersion: 1 m_State: {fileID: -5615459309368676638} - m_Position: {x: 260, y: -10, z: 0} + m_Position: {x: 560, y: 90, z: 0} - serializedVersion: 1 m_State: {fileID: -4316900719387780663} m_Position: {x: 260, y: 170, z: 0} + - serializedVersion: 1 + m_State: {fileID: -5723871321714695223} + m_Position: {x: 704.1478, y: -596.24896, z: 0} m_ChildStateMachines: [] m_AnyStateTransitions: [] m_EntryTransitions: [] @@ -157,3 +210,25 @@ AnimatorStateMachine: m_ExitPosition: {x: 800, y: 120, z: 0} m_ParentStateMachinePosition: {x: 800, y: 20, z: 0} m_DefaultState: {fileID: -5615459309368676638} +--- !u!1101 &6351061945338306534 +AnimatorStateTransition: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_Conditions: [] + m_DstStateMachine: {fileID: 0} + m_DstState: {fileID: -5615459309368676638} + m_Solo: 0 + m_Mute: 0 + m_IsExit: 0 + serializedVersion: 3 + m_TransitionDuration: 0.25 + m_TransitionOffset: 0 + m_ExitTime: 0.75 + m_HasExitTime: 1 + m_HasFixedDuration: 1 + m_InterruptionSource: 0 + m_OrderedInterruption: 1 + m_CanTransitionToSelf: 1 diff --git a/Assets/Animations/Monsters/ClawClawRough/ClawClawRough_die.anim b/Assets/Animations/Monsters/ClawClawRough/ClawClawRough_die.anim index 1c2f3ec..99c5279 100644 --- a/Assets/Animations/Monsters/ClawClawRough/ClawClawRough_die.anim +++ b/Assets/Animations/Monsters/ClawClawRough/ClawClawRough_die.anim @@ -1705,7 +1705,7 @@ AnimationClip: m_Level: 0 m_CycleOffset: 0 m_HasAdditiveReferencePose: 0 - m_LoopTime: 1 + m_LoopTime: 0 m_LoopBlend: 0 m_LoopBlendOrientation: 0 m_LoopBlendPositionY: 0 diff --git a/Assets/Animations/Monsters/ClawClawRough/ClawClawRough_idle.anim b/Assets/Animations/Monsters/ClawClawRough/ClawClawRough_idle.anim index 0d1d26c..8095860 100644 --- a/Assets/Animations/Monsters/ClawClawRough/ClawClawRough_idle.anim +++ b/Assets/Animations/Monsters/ClawClawRough/ClawClawRough_idle.anim @@ -774,7 +774,7 @@ AnimationClip: m_Level: 0 m_CycleOffset: 0 m_HasAdditiveReferencePose: 0 - m_LoopTime: 1 + m_LoopTime: 0 m_LoopBlend: 0 m_LoopBlendOrientation: 0 m_LoopBlendPositionY: 0 diff --git a/Assets/Animations/Monsters/ClawClawRough/ClawClawRough_walk.anim b/Assets/Animations/Monsters/ClawClawRough/ClawClawRough_walk.anim index 499ebf7..93ee7e1 100644 --- a/Assets/Animations/Monsters/ClawClawRough/ClawClawRough_walk.anim +++ b/Assets/Animations/Monsters/ClawClawRough/ClawClawRough_walk.anim @@ -733,7 +733,7 @@ AnimationClip: m_Level: 0 m_CycleOffset: 0 m_HasAdditiveReferencePose: 0 - m_LoopTime: 1 + m_LoopTime: 0 m_LoopBlend: 0 m_LoopBlendOrientation: 0 m_LoopBlendPositionY: 0 diff --git a/Assets/Scripts/Ally/Ally.cs b/Assets/Scripts/Ally/Ally.cs index 55fa7b9..6cabeb3 100644 --- a/Assets/Scripts/Ally/Ally.cs +++ b/Assets/Scripts/Ally/Ally.cs @@ -17,12 +17,13 @@ public class Ally : Entity //Attack Cooldown if(AttackSpeed < AttackSpeedWait) { - Enemy.Hp-=AttackDamage; + Enemy.hit(AttackDamage); Debug.Log("Opponent Hp = " + Enemy.Hp); //Kill if no hp if(Enemy.Hp <= 0) { - Destroy(Enemy); + IsEnemyDetected = false; + Enemy.death(); } AttackSpeedWait = 0f; diff --git a/Assets/Scripts/AnimationEntity.cs b/Assets/Scripts/AnimationEntity.cs index 7d80a9f..97e59fd 100644 --- a/Assets/Scripts/AnimationEntity.cs +++ b/Assets/Scripts/AnimationEntity.cs @@ -25,9 +25,18 @@ public class AnimationEntity : MonoBehaviour _animator_entity.Play("idle", 0, 0f); } + public void Walk() { + _animator_entity.Play("walk", 0, 0f); + } + public void Attack() { _animator_entity.Play("attack", 0, 0f); _doSomething = true; } + public void Die() { + _animator_entity.Play("die", 0, 0f); + _doSomething = true; + } + } diff --git a/Assets/Scripts/Detection.cs b/Assets/Scripts/Detection.cs index 44adf33..be8b19e 100644 --- a/Assets/Scripts/Detection.cs +++ b/Assets/Scripts/Detection.cs @@ -22,30 +22,35 @@ public class Detection : MonoBehaviour void OnTriggerEnter2D(Collider2D other) { //Projectiles detection + damage deal - if(_projectileDamage > 0 && other.gameObject.GetComponent() == _entityLinked) { + if(_entityLinked is not null) { + if(_projectileDamage > 0 && other.gameObject.GetComponent() == _entityLinked) { + + _entityLinked.hit(_projectileDamage); + //Kill if no hp + if(other.gameObject.GetComponent().Hp <= 0) { + other.gameObject.GetComponent().death(); + _entityLinked = null; + } - other.gameObject.GetComponent().Hp -= _projectileDamage; - //Kill if no hp - if(other.gameObject.GetComponent().Hp <= 0) { - Destroy(other.gameObject); } - } + } void OnTriggerStay2D(Collider2D other) { + if(_entityLinked is not null) { + if(_entityLinked.Enemy == null) { + //Detect the enemy and inform the Ally + if (other.gameObject.tag == "Opponent" && _entityLinked is Ally) { + _entityLinked.IsEnemyDetected = true; + _entityLinked.Enemy = other.gameObject.GetComponent(); + } - if(_entityLinked.Enemy == null) { - //Detect the enemy and inform the Ally - if (other.gameObject.tag == "Opponent" && _entityLinked is Ally) { - _entityLinked.IsEnemyDetected = true; - _entityLinked.Enemy = other.gameObject.GetComponent(); - } - - //Detect the enemy and inform the Opponent - if (other.gameObject.tag == "Ally" && _entityLinked is Opponent) { - _entityLinked.IsEnemyDetected = true; - _entityLinked.Enemy = other.gameObject.GetComponent(); + //Detect the enemy and inform the Opponent + if (other.gameObject.tag == "Ally" && _entityLinked is Opponent) { + _entityLinked.IsEnemyDetected = true; + _entityLinked.Enemy = other.gameObject.GetComponent(); + } } } @@ -53,9 +58,11 @@ public class Detection : MonoBehaviour void OnTriggerExit2D(Collider2D other) { - if(_projectileDamage == 0) { - if ((other.gameObject.tag == "Opponent" && _entityLinked is Ally) || (other.gameObject.tag == "Ally" && _entityLinked is Opponent)) { - _entityLinked.IsEnemyDetected = false; + if(_entityLinked is not null) { + if(_projectileDamage == 0) { + if ((other.gameObject.tag == "Opponent" && _entityLinked is Ally) || (other.gameObject.tag == "Ally" && _entityLinked is Opponent)) { + _entityLinked.IsEnemyDetected = false; + } } } diff --git a/Assets/Scripts/Entity.cs b/Assets/Scripts/Entity.cs index 3a8eee1..1c57bb0 100644 --- a/Assets/Scripts/Entity.cs +++ b/Assets/Scripts/Entity.cs @@ -16,11 +16,65 @@ public class Entity : LevelObject private float _attack_speed; private float _attack_speed_wait = 0f; private AnimationEntity _animation; + private Shader shaderGUItext; + private Shader shaderSpritesDefault; //Enemy Spotted private bool _isEnemyDetected = false; private Entity _enemy; + //Methods + public void death() { + _animation.Die(); + Invoke("dying", 0.1f); + } + + void dying() { + SpriteRenderer[] spriteRenderers; + spriteRenderers = GetComponentsInChildren(); + + + foreach (SpriteRenderer renderer in spriteRenderers) + { + Color currentColor = renderer.color; + currentColor.a = currentColor.a - 0.1f; + renderer.color = currentColor; + } + + if(spriteRenderers[0].color.a > 0f) { + Invoke("dying", 0.1f); + }else { + Destroy(gameObject); + } + + } + + public void hit(int damage) { + + _hp-=damage; + + SpriteRenderer[] spriteRenderers; + spriteRenderers = GetComponentsInChildren(); + shaderGUItext = Shader.Find("GUI/Text Shader"); + shaderSpritesDefault = Shader.Find("Sprites/Default"); + + foreach (SpriteRenderer renderer in spriteRenderers) + { + renderer.material.shader = shaderGUItext; + } + Invoke("returnNormalColor", 0.1f); + } + + void returnNormalColor() { + SpriteRenderer[] spriteRenderers; + spriteRenderers = GetComponentsInChildren(); + + foreach (SpriteRenderer renderer in spriteRenderers) + { + renderer.material.shader = shaderSpritesDefault; + } + } + //GETTERS AND SETTERS public int Hp diff --git a/Assets/Scripts/Opponent/Opponent.cs b/Assets/Scripts/Opponent/Opponent.cs index 822b8ad..ef8a095 100644 --- a/Assets/Scripts/Opponent/Opponent.cs +++ b/Assets/Scripts/Opponent/Opponent.cs @@ -11,6 +11,7 @@ public class Opponent : Entity void Start() { _rigidbody = GetComponent(); + Animation = gameObject.AddComponent(); } void Update() { @@ -29,12 +30,14 @@ public class Opponent : Entity //Attack Cooldown if(AttackSpeed < AttackSpeedWait) { - Enemy.Hp-=AttackDamage; + Animation.Attack(); + + Enemy.hit(AttackDamage); Debug.Log("Ally Hp = " + Enemy.Hp); //Kill if no hp if(Enemy.Hp <= 0) { - Destroy(Enemy); + Enemy.death(); } AttackSpeedWait = 0f;