StepBackScript.cs 1.63 KiB
using System.Collections;
using UnityEngine;
[RequireComponent(typeof(Rigidbody2D))]
public class StepBackScript : AtkSkills
{
private Rigidbody2D rb;
private bool isActive;
// Use this for initialization
void Start ()
{
controller = GetComponent<Controller>();
animatorController = GetComponent<Animator>();
rb = GetComponent<Rigidbody2D>();
isActive = false;
usingAxis = false;
}
// Update is called once per frame
private void Update()
{
if (controller.hasStamina(energyCost) && controller.getStepBackInput() == 1)
{
if (controller.isMyturn() && !controller.isSkillUsing() && !usingAxis)
{
StopCoroutine("move");
animatorController.SetTrigger("StepBack");
consumeEnergy(energyCost);
}
usingAxis = true;
}
else
{
usingAxis = false;
}
}
private IEnumerator stepBack()
{
controller.updateMovementLockStates();
while(isActive)
{
rb.velocity = new Vector2(1, controller.currentHand) * controller.getSpeed() * SettingsPersistance.INSTANCE.difficulty.getSpeedModifier();
yield return null;
}
controller.updateMovementLockStates();
}
private void updateState()
{
isActive = isActive == true? false : true;
StartCoroutine(stepBack());
}
public virtual void OnDisable()
{
StepBackBehaviour.action -= updateState;
}
public virtual void OnEnable()
{
StepBackBehaviour.action += updateState;
}
}