1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Events;
- using KairoEngine.Core;
- namespace KairoEngine.CharacterSystem
- {
- /// <summary>
- /// Action to move a character in a certain direction and speed.
- /// </summary>
- 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;
- /// <summary>
- /// Action that will make a character follow a target playing a zombie animation.
- /// </summary>
- /// <param name="character">The CharacterController performing the action.</param>
- /// <param name="targetPosition">The target position that the attack will hit.</param>
- /// <param name="varient">Use "AttackL", "AttackR" or "Attack".</param>
- 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;
- }
- }
- }
|