Ludum Dare 50 Theme: Delay the inevitable
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
991 B

using Enemies.States;
using UnityEngine;
namespace Enemies
{
public class TargetState: IState
{
private readonly Enemy context;
public TargetState(Enemy context)
{
this.context = context;
}
public void Enter()
{
Debug.Log("Entering Target State");
context.currentState = Enemy.States.Target;
//Find nearest target
GameObject player = GameObject.FindWithTag("Player");
GameObject house = GameObject.FindWithTag("Base");
GameObject nearest = player; ;
if (Vector3.Distance(player.transform.position, context.transform.position) > Vector3.Distance(house.transform.position, context.transform.position))
{
nearest = house;
}
context.target = nearest;
}
public void Execute()
{
}
public void Exit()
{
}
}
}