Skip to content

Commit

Permalink
Added damage indication and fixed other bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedMediouni1 committed May 3, 2024
1 parent 186b561 commit 6206aa1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
1 change: 1 addition & 0 deletions Assets/Prefab/Ashman_Enemy3.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ MonoBehaviour:
damage: 0
HealthEnemy: 25
healthEnemy: 0
switchDuration: 0.3
--- !u!50 &4003872555974094568
Rigidbody2D:
serializedVersion: 4
Expand Down
2 changes: 1 addition & 1 deletion Assets/Prefab/BoomEnemy.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -4951,7 +4951,7 @@ CircleCollider2D:
m_CallbackLayers:
serializedVersion: 2
m_Bits: 4294967295
m_IsTrigger: 0
m_IsTrigger: 1
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0.0025429726, y: 0}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Prefab/HealthUp.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ BoxCollider2D:
m_CallbackLayers:
serializedVersion: 2
m_Bits: 4294967295
m_IsTrigger: 0
m_IsTrigger: 1
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: -0.00037294626, y: 0.00057081133}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Prefab/SpeedUp.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -4974,7 +4974,7 @@ BoxCollider2D:
m_CallbackLayers:
serializedVersion: 2
m_Bits: 4294967295
m_IsTrigger: 0
m_IsTrigger: 1
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: -0.0007728264, y: 0.0022977144}
Expand Down
35 changes: 28 additions & 7 deletions Assets/Scripts/AiDamage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ public class AiDamage : MonoBehaviour
public int HealthEnemy = 25;
public int healthEnemy;

public Sprite normalSprite; // Reference to the normal sprite
public Sprite damageSprite; // Reference to the sprite to switch to when taking damage
public float switchDuration = 0.5f; // Duration to switch to damage sprite (in seconds)
public int numberflashes;
float switchDuration = 0.1f; // Duration to switch to damage sprite (in seconds)
int numberflashes = 3;

private SpriteRenderer spriteRenderer; // Reference to the SpriteRenderer component

Expand Down Expand Up @@ -42,8 +40,6 @@ private void OnCollisionEnter2D(Collision2D collision)
}
public void EDamage(int damage)
{


healthEnemy -= damage;
}

Expand All @@ -53,10 +49,35 @@ private void OnTriggerEnter2D(Collider2D collision)
{

playerHealth.TakeDamage(damage);
GetComponent<SpriteRenderer>().material.color = Color.red;
StartCoroutine(FlashRed());

}
if(collision.gameObject.tag == "PlayerBullet")
{
StartCoroutine(FlashRed());
}
}
IEnumerator FlashRed()
{

GetComponent<SpriteRenderer>().material.color = Color.red;
yield return new WaitForSeconds(switchDuration);
GetComponent<SpriteRenderer>().material.color = Color.white;
yield return new WaitForSeconds(switchDuration);
GetComponent<SpriteRenderer>().material.color = Color.red;
yield return new WaitForSeconds(switchDuration);
GetComponent<SpriteRenderer>().material.color = Color.white;
yield return new WaitForSeconds(switchDuration);
GetComponent<SpriteRenderer>().material.color = Color.red;
yield return new WaitForSeconds(switchDuration);
GetComponent<SpriteRenderer>().material.color = Color.white;
yield return new WaitForSeconds(switchDuration);
GetComponent<SpriteRenderer>().material.color = Color.red;
yield return new WaitForSeconds(switchDuration);
GetComponent<SpriteRenderer>().material.color = Color.white;
yield return new WaitForSeconds(switchDuration);
}



}

0 comments on commit 6206aa1

Please sign in to comment.