Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace Enemy {
- public abstract class Enemy : MonoBehaviour {
- // Enemy states
- protected enum EnemyStates {
- Patrol,
- Alert,
- Hostile
- }
- // How far the enemy can see
- protected int visionLength;
- // How far the enemy will walk from its spawn point
- protected int walkingDistance;
- // List of enemies active in the game
- List<Enemy> enemies = new List<Enemy>();
- protected void Start() {
- // Set every Enemy to do their default state
- DoAction(EnemyStates.Patrol);
- }
- protected void Update() {
- for(int i = 0; i < enemies.Count; i++) {
- if (enemies[i].ShouldChangeState()) {
- enemies[i].UpdateEnemyState();
- }
- }
- }
- public virtual void UpdateEnemyState() {
- }
- protected void DoAction(EnemyStates enemyState) {
- switch(enemyState) {
- case EnemyStates.Patrol:
- // Patrol
- break;
- case EnemyStates.Alert:
- // Alert
- break;
- case EnemyStates.Hostile:
- // Hostile
- break;
- }
- }
- protected virtual bool ShouldChangeState() {
- // If player is seen by guard etc. return true
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement