diff --git a/Assets/Prefabs/Castle.prefab b/Assets/Prefabs/Castle.prefab index e753cc0..c0b6425 100644 --- a/Assets/Prefabs/Castle.prefab +++ b/Assets/Prefabs/Castle.prefab @@ -62,7 +62,7 @@ BoxCollider2D: m_Enabled: 1 m_Density: 1 m_Material: {fileID: 0} - m_IsTrigger: 0 + m_IsTrigger: 1 m_UsedByEffector: 0 m_UsedByComposite: 0 m_Offset: {x: 0, y: 0} diff --git a/Assets/Prefabs/Monsters/ClawClawRough_monster.prefab b/Assets/Prefabs/Monsters/ClawClawRough_monster.prefab index aa9f0ae..118f159 100644 --- a/Assets/Prefabs/Monsters/ClawClawRough_monster.prefab +++ b/Assets/Prefabs/Monsters/ClawClawRough_monster.prefab @@ -106,7 +106,7 @@ BoxCollider2D: m_Enabled: 1 m_Density: 1 m_Material: {fileID: 0} - m_IsTrigger: 0 + m_IsTrigger: 1 m_UsedByEffector: 0 m_UsedByComposite: 0 m_Offset: {x: 0, y: 0} diff --git a/Assets/Prefabs/Sticks/Harversters/minerStick.prefab b/Assets/Prefabs/Sticks/Harversters/minerStick.prefab index 2daa95c..2b70e35 100644 --- a/Assets/Prefabs/Sticks/Harversters/minerStick.prefab +++ b/Assets/Prefabs/Sticks/Harversters/minerStick.prefab @@ -495,7 +495,7 @@ BoxCollider2D: m_Enabled: 1 m_Density: 1 m_Material: {fileID: 0} - m_IsTrigger: 0 + m_IsTrigger: 1 m_UsedByEffector: 0 m_UsedByComposite: 0 m_Offset: {x: 0, y: 0} diff --git a/Assets/Prefabs/Sticks/archerStick.prefab b/Assets/Prefabs/Sticks/archerStick.prefab index 811ad02..b375de6 100644 --- a/Assets/Prefabs/Sticks/archerStick.prefab +++ b/Assets/Prefabs/Sticks/archerStick.prefab @@ -643,7 +643,7 @@ BoxCollider2D: m_Enabled: 1 m_Density: 1 m_Material: {fileID: 0} - m_IsTrigger: 0 + m_IsTrigger: 1 m_UsedByEffector: 0 m_UsedByComposite: 0 m_Offset: {x: 0, y: 0} diff --git a/Assets/Prefabs/Sticks/baseStick.prefab b/Assets/Prefabs/Sticks/baseStick.prefab index ef157c6..492fdd4 100644 --- a/Assets/Prefabs/Sticks/baseStick.prefab +++ b/Assets/Prefabs/Sticks/baseStick.prefab @@ -511,7 +511,7 @@ BoxCollider2D: m_Enabled: 1 m_Density: 1 m_Material: {fileID: 0} - m_IsTrigger: 0 + m_IsTrigger: 1 m_UsedByEffector: 0 m_UsedByComposite: 0 m_Offset: {x: 0, y: 0} diff --git a/Assets/Prefabs/Sticks/farmersAssociation.prefab b/Assets/Prefabs/Sticks/farmersAssociation.prefab index c7536b5..94ad7c2 100644 --- a/Assets/Prefabs/Sticks/farmersAssociation.prefab +++ b/Assets/Prefabs/Sticks/farmersAssociation.prefab @@ -1176,7 +1176,7 @@ BoxCollider2D: m_Enabled: 1 m_Density: 1 m_Material: {fileID: 0} - m_IsTrigger: 0 + m_IsTrigger: 1 m_UsedByEffector: 0 m_UsedByComposite: 0 m_Offset: {x: 0, y: 0} diff --git a/Assets/Prefabs/baseMonster.prefab b/Assets/Prefabs/baseMonster.prefab index fc884de..75f220e 100644 --- a/Assets/Prefabs/baseMonster.prefab +++ b/Assets/Prefabs/baseMonster.prefab @@ -67,7 +67,7 @@ BoxCollider2D: m_Enabled: 1 m_Density: 1 m_Material: {fileID: 0} - m_IsTrigger: 0 + m_IsTrigger: 1 m_UsedByEffector: 0 m_UsedByComposite: 0 m_Offset: {x: 0, y: 0} diff --git a/Assets/Prefabs/baseProjectile.prefab b/Assets/Prefabs/baseProjectile.prefab index b3a05a3..cbab2f8 100644 --- a/Assets/Prefabs/baseProjectile.prefab +++ b/Assets/Prefabs/baseProjectile.prefab @@ -107,7 +107,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 01782bd631a6e1446956ed140a24c530, type: 3} m_Name: m_EditorClassIdentifier: - _detectionLinked: {fileID: 3172728477976940186} + _detectionLinked: {fileID: 4130391605812397686} _angle: 10 _speed: 1 --- !u!1 &6962989256011107503 @@ -204,7 +204,7 @@ GameObject: m_Component: - component: {fileID: 6802302589573039538} - component: {fileID: 7006189111012443782} - - component: {fileID: 3172728477976940186} + - component: {fileID: 4130391605812397686} m_Layer: 0 m_Name: detection m_TagString: Untagged @@ -253,7 +253,7 @@ BoxCollider2D: serializedVersion: 2 m_Size: {x: 0.3744527, y: 0.17825907} m_EdgeRadius: 0 ---- !u!114 &3172728477976940186 +--- !u!114 &4130391605812397686 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} diff --git a/Assets/Scripts/AnimationEntity.cs b/Assets/Scripts/AnimationEntity.cs index 8890e82..b3b071a 100644 --- a/Assets/Scripts/AnimationEntity.cs +++ b/Assets/Scripts/AnimationEntity.cs @@ -8,6 +8,7 @@ public class AnimationEntity : MonoBehaviour private Animator _animatorEntity; private bool _doSomething = false; private bool _isDead = false; + private bool _isWalking = false; void Start() { @@ -21,6 +22,7 @@ public class AnimationEntity : MonoBehaviour { PlayIdleAnim(); _doSomething = false; + _isWalking = false; } } @@ -35,6 +37,7 @@ public class AnimationEntity : MonoBehaviour { if(!_isDead) { _animatorEntity.Play("walk", 0, 0f); + _isWalking = true; } } @@ -53,4 +56,11 @@ public class AnimationEntity : MonoBehaviour _isDead = true; } + //SETTER GETTER + public bool IsWalking + { + get { return _isWalking; } + set { _isWalking = value; } + } + } diff --git a/Assets/Scripts/Detection.cs b/Assets/Scripts/Detection.cs index b5bab1c..dda1736 100644 --- a/Assets/Scripts/Detection.cs +++ b/Assets/Scripts/Detection.cs @@ -18,6 +18,7 @@ public class Detection : MonoBehaviour //If it's a projectile damage > 0 private int _projectileDamage = 0; + private float _distanceMin = 100f; void OnTriggerEnter2D(Collider2D other) { @@ -29,9 +30,10 @@ public class Detection : MonoBehaviour //Kill if no hp if(other.gameObject.GetComponent().Hp <= 0) { other.gameObject.GetComponent().Death(); - _entityLinked = null; } + _entityLinked = null; + } } @@ -39,21 +41,32 @@ public class Detection : MonoBehaviour void OnTriggerStay2D(Collider2D other) { - if(_entityLinked != null) { - if(_entityLinked.Enemy == null) { + if(_entityLinked != null && _projectileDamage == 0) { + //Detect the enemy and inform the Ally - if (other.gameObject.tag == "Opponent" && _entityLinked is Ally) { - _entityLinked.IsEnemyDetected = true; - _entityLinked.Enemy = other.gameObject.GetComponent(); + if (other.gameObject.tag == "Opponent" && _entityLinked.gameObject.tag == "Ally") { + if(other.gameObject.transform.position.x <= _distanceMin) { + _distanceMin = other.gameObject.transform.position.x; + _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(); - } - } + if (other.gameObject.tag == "Ally" && _entityLinked.gameObject.tag == "Opponent" ) { + if(other.gameObject.transform.position.x <= _distanceMin) { + _distanceMin = other.gameObject.transform.position.x; + _entityLinked.IsEnemyDetected = true; + _entityLinked.Enemy = other.gameObject.GetComponent(); + } + } + + if(_entityLinked.Enemy == null && _distanceMin != 100f) { + _distanceMin = 100f; + } } + + } diff --git a/Assets/Scripts/Entity.cs b/Assets/Scripts/Entity.cs index 688aa63..598493b 100644 --- a/Assets/Scripts/Entity.cs +++ b/Assets/Scripts/Entity.cs @@ -82,6 +82,12 @@ public class Entity : LevelObject } } + public void Move() { + if(!_animation.IsWalking) { + _animation.PlayWalkAnim(); + } + } + //GETTERS AND SETTERS public int Hp diff --git a/Assets/Scripts/Opponent/Opponent.cs b/Assets/Scripts/Opponent/Opponent.cs index 19e8221..14a2451 100644 --- a/Assets/Scripts/Opponent/Opponent.cs +++ b/Assets/Scripts/Opponent/Opponent.cs @@ -18,14 +18,18 @@ public class Opponent : Entity void Update() { - - _movementVector.x = -Time.deltaTime * Speed; - - transform.position += (Vector3)_movementVector; - if(IsEnemyDetected) { AttackEnemy(); + }else { + _movementVector.x = -Time.deltaTime * Speed; + + transform.position += (Vector3)_movementVector; + + Move(); } + + + }