Create Creeper script

This commit is contained in:
2024-10-28 15:39:01 -07:00
parent 49937d80b5
commit 76a807f599
2 changed files with 23 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
using UnityEngine;
using System.Collections;
public class Creeper : Ratbot
{
float countdown;
void Update() {
if (Vector3.Distance(player.transform.position, transform.position) > 5) {
MoveTowardsPlayer(moveSpeed);
float newTime = countdown + Time.deltaTime;
countdown = (newTime < 1) ? newTime : 1;
} else {
countdown -= Time.deltaTime;
if (countdown < 0) Explode();
}
}
void Explode() {
Destroy(gameObject);
}
}