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 8264e43..7f773f1 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} @@ -576,6 +576,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: _entity: {fileID: 313037212318601125} + _projectile: {fileID: 0} --- !u!1 &1776168629768863343 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/baseArcher.prefab b/Assets/Prefabs/baseArcher.prefab index f2f1688..8f76d59 100644 --- a/Assets/Prefabs/baseArcher.prefab +++ b/Assets/Prefabs/baseArcher.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/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 d4f38b5..28ca37e 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: 2 --- !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.2, y: 0.1} m_EdgeRadius: 0 ---- !u!114 &3172728477976940186 +--- !u!114 &4130391605812397686 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} diff --git a/Assets/Prefabs/baseStick.prefab b/Assets/Prefabs/baseStick.prefab index b1bfea4..1345009 100644 --- a/Assets/Prefabs/baseStick.prefab +++ b/Assets/Prefabs/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} @@ -748,6 +748,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: _entity: {fileID: 8585520847943034727} + _projectile: {fileID: 0} --- !u!1 &6962989255885988245 GameObject: m_ObjectHideFlags: 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 7ba16df..0ce1d9b 100644 --- a/Assets/Scripts/Entity.cs +++ b/Assets/Scripts/Entity.cs @@ -81,6 +81,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..7a43575 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(); } + + + }