Health system for ratbots, can now stab ratbots

This commit is contained in:
2024-10-20 00:40:53 -07:00
parent d8c8e88220
commit 81b0797774
4 changed files with 135 additions and 2 deletions

View File

@@ -4,6 +4,8 @@ public class Teo : MonoBehaviour
{
public float health = 100;
public float moveSpeed = 10;
public float swingRange = 3;
public float damageStrength = 10;
Rigidbody2D controller;
GameState gameState;
// Start is called once before the first execution of Update after the MonoBehaviour is created
@@ -18,5 +20,21 @@ public class Teo : MonoBehaviour
Input.GetAxis("Horizontal"),
Input.GetAxis("Vertical")
).normalized * moveSpeed;
if (Input.GetMouseButtonDown(0)) {
RaycastHit2D[] hits = Physics2D.CircleCastAll(
transform.position,
swingRange,
new Vector2(
Screen.width/2 - Input.mousePosition.x,
Screen.height/2 - Input.mousePosition.y
)
);
foreach (RaycastHit2D hit in hits) {
Ratbot ratbot = hit.collider.GetComponent<Ratbot>();
if (ratbot == null) continue;
ratbot.Damage(damageStrength);
}
}
}
}