Skip to content
Snippets Groups Projects
StepBackScript.cs 1.76 KiB
Newer Older
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(Animator))]
[RequireComponent(typeof(Controller))]
[RequireComponent(typeof(Rigidbody2D))]

public class StepBackScript : MonoBehaviour
{
    private Animator animatorController;
    private Controller controller;
    private Rigidbody2D rb;
    private bool isActive;
    private bool usingAxis;
    [SerializeField] float speedModifier;
    // 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.getStepBackInput() == 1)
            if (controller.isMyturn() && !controller.isSkillUsing() && !usingAxis)
            {
                animatorController.SetTrigger("StepBack");
            }
            usingAxis = true;
        }
        else
        {
            usingAxis = false;
        controller.updateMovementLockStates();
            rb.velocity = new Vector2(1, controller.currentHand) * controller.getSpeed() * speedModifier;
        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;
    }