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

@@ -9,20 +9,20 @@ public class Ratbot : MonoBehaviour
float lastDamageTime;
GameState gameState;
GameObject player;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
void Start() {
// Set gameState and player objects
player = GameObject.FindGameObjectWithTag("Player");
gameState = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameState>();
}
// Update is called once per frame
void Update()
{
void Update() {
// Constantly move towards player
Rigidbody2D controller = GetComponent<Rigidbody2D>();
Vector2 direction = (player.transform.position - transform.position).normalized;
controller.linearVelocity = direction*moveSpeed;
}
void OnCollisionStay2D(Collision2D collision) {
// Deal damage when colliding with the player on a 0.5 second cooldown
if (collision.gameObject.tag != "Player") return;
@@ -30,6 +30,8 @@ public class Ratbot : MonoBehaviour
lastDamageTime = Time.fixedTime;
collision.gameObject.GetComponent<Teo>().health -= damageStrength;
}
// Die if health below zero
public void Damage(float hurtyAmount) {
health -= hurtyAmount;
if (health <= 0) {