Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class Enemy : MonoBehaviour
- {
- public float health = 100f;
- public float speed = 3f;
- public Transform target;
- void Update()
- {
- Move();
- CheckDeath();
- }
- void Move()
- {
- if (!target) return;
- Vector3 dir = (target.position - transform.position).normalized;
- transform.position += dir * speed * Time.deltaTime;
- }
- public void TakeDamage(float dmg)
- {
- health -= dmg;
- }
- void CheckDeath()
- {
- if (health <= 0f)
- Destroy(gameObject);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment