using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using KairoEngine.Core;
namespace KairoEngine.CharacterSystem
{
///
/// Action to move a character in a certain direction and speed.
///
public class ZombieAttackAction : IAction
{
CharacterController character; // Reference to the character that will move
Vector3 targetPosition;
string varient;
bool done = false;
float counter = 0f;
bool hit = false;
///
/// Action that will make a character follow a target playing a zombie animation.
///
/// The CharacterController performing the action.
/// The target position that the attack will hit.
/// Use "AttackL", "AttackR" or "Attack".
public ZombieAttackAction(CharacterController character, Vector3 targetPosition, string varient)
{
this.character = character;
this.targetPosition = targetPosition;
this.varient = varient;
this.counter = 0f;
}
public void Start()
{
if(varient == "AttackL") character.animator.SetTrigger("AttackL");
else if(varient == "AttackR") character.animator.SetTrigger("AttackR");
else character.animator.SetTrigger("Attack");
GenericEvents.StartListening(character.unique_name + "-AnimationHit", Hit);
}
public void Update()
{
if(hit)
{
counter += Time.deltaTime;
if(counter > 0.2f)
{
End();
}
}
}
public void Hit()
{
hit = true;
GenericEvents.StopListening(character.unique_name + "-AnimationHit", End);
if(varient == "AttackL") character.leftUnarmedObject.SetActive(true);
else if(varient == "AttackR") character.rightUnarmedObject.SetActive(true);
else
{
character.rightUnarmedObject.SetActive(true);
character.leftUnarmedObject.SetActive(true);
}
}
public void End()
{
done = true;
character.rightUnarmedObject.SetActive(false);
character.leftUnarmedObject.SetActive(false);
}
public bool IsDone()
{
return done;
}
}
}