Hopefully there's okay comments on things now
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user