Pull request #36: AJout detection de l'ennemi le plus proche, correction bug collision, correction bug monstres attaque de loin
Merge in CGD/gather-and-defend from animation_unites to main * commit '33e5d14c9ef1223a17ea1d5335b2f60ab4ba5938': isTrigger ajouté restored broken prefabs no message AJout detection de l'ennemi le plus proche, correction bug collision, correction bug monstres attaque de loin
This commit is contained in:
commit
3d919455e9
@ -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}
|
||||
|
||||
@ -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}
|
||||
|
||||
@ -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}
|
||||
|
||||
@ -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}
|
||||
|
||||
@ -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}
|
||||
|
||||
@ -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}
|
||||
|
||||
@ -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}
|
||||
|
||||
@ -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}
|
||||
|
||||
@ -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; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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<Entity>().Hp <= 0) {
|
||||
other.gameObject.GetComponent<Entity>().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) {
|
||||
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<Entity>();
|
||||
}
|
||||
}
|
||||
|
||||
//Detect the enemy and inform the Opponent
|
||||
if (other.gameObject.tag == "Ally" && _entityLinked is Opponent) {
|
||||
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<Entity>();
|
||||
}
|
||||
}
|
||||
|
||||
if(_entityLinked.Enemy == null && _distanceMin != 100f) {
|
||||
_distanceMin = 100f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -82,6 +82,12 @@ public class Entity : LevelObject
|
||||
}
|
||||
}
|
||||
|
||||
public void Move() {
|
||||
if(!_animation.IsWalking) {
|
||||
_animation.PlayWalkAnim();
|
||||
}
|
||||
}
|
||||
|
||||
//GETTERS AND SETTERS
|
||||
|
||||
public int Hp
|
||||
|
||||
@ -18,15 +18,19 @@ public class Opponent : Entity
|
||||
|
||||
void Update()
|
||||
{
|
||||
|
||||
if(IsEnemyDetected) {
|
||||
AttackEnemy();
|
||||
}else {
|
||||
_movementVector.x = -Time.deltaTime * Speed;
|
||||
|
||||
transform.position += (Vector3)_movementVector;
|
||||
|
||||
if(IsEnemyDetected) {
|
||||
AttackEnemy();
|
||||
Move();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void AttackEnemy()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user