Hopefully there's okay comments on things now

This commit is contained in:
2024-10-20 02:47:43 -07:00
parent eb47adf2d2
commit fd6657047b
6 changed files with 35 additions and 9 deletions

View File

@@ -6,8 +6,10 @@ public class Teo : MonoBehaviour
public float moveSpeed = 10;
public float swingRange = 3;
public float damageStrength = 10;
public float attackCooldownSeconds = 2;
Rigidbody2D controller;
GameState gameState;
float lastAttackTime;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start() {
controller = GetComponent<Rigidbody2D>();
@@ -16,12 +18,15 @@ public class Teo : MonoBehaviour
// Update is called once per frame
void Update() {
// Move player
controller.linearVelocity = new Vector2 (
Input.GetAxis("Horizontal"),
Input.GetAxis("Vertical")
).normalized * moveSpeed;
if (Input.GetMouseButtonDown(0)) {
// Attack on click if not on cooldown
if (Input.GetMouseButtonDown(0) && Time.fixedTime > lastAttackTime + attackCooldownSeconds) {
// Get all objects in range in the direction of cursor
RaycastHit2D[] hits = Physics2D.CircleCastAll(
transform.position,
swingRange,
@@ -30,6 +35,7 @@ public class Teo : MonoBehaviour
Screen.height/2 - Input.mousePosition.y
)
);
// Damage all ratbots in scanned area
foreach (RaycastHit2D hit in hits) {
Ratbot ratbot = hit.collider.GetComponent<Ratbot>();
if (ratbot == null) continue;