Skip to content
This repository was archived by the owner on Apr 10, 2023. It is now read-only.

Commit 91bd95a

Browse files
committed
Apply Interface Segregation Principle
1 parent 2d1d2e8 commit 91bd95a

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
public interface IHittable
2+
{
3+
void GetHit();
4+
}

SOLID/SOLID/Assets/Scripts/IHittable.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SOLID/SOLID/Assets/Scripts/NPCEnemy.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public class NPCEnemy : NPC
1+
using UnityEngine;
2+
3+
public class NPCEnemy : NPC, IHittable
24
{
35
public string text = "I deal 10 physical damage ( •̀ᴗ•́ )و ̑̑ ";
46

@@ -13,4 +15,9 @@ protected override string GetText()
1315
{
1416
return text;
1517
}
18+
19+
public void GetHit()
20+
{
21+
Debug.Log("Ouch!");
22+
}
1623
}

SOLID/SOLID/Assets/Scripts/PlayerAIInteractions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ public void Interact(bool isSpriteFlipped)
1515
{
1616
npc.Interact();
1717
}
18+
19+
if (hit.collider.TryGetComponent(out IHittable hittable))
20+
{
21+
hittable?.GetHit();
22+
}
1823
}
1924
}
2025
}

0 commit comments

Comments
 (0)