Skip to content
Snippets Groups Projects
CrossOverScript.cs 1.36 KiB
Newer Older
using System.Collections;
using UnityEngine;

[RequireComponent(typeof(Rigidbody2D))]
public class CrossOverScript : AtkSkills
william's avatar
william committed
	private Rigidbody2D rb;
	private bool isActive;
	[SerializeField] float speedModifier;
william's avatar
william committed
	// Use this for initialization
	void Start()
	{
		controller = GetComponent<Controller>();
		animatorController = GetComponent<Animator>();
		rb = GetComponent<Rigidbody2D>();
		isActive = false;
		usingAxis = false;
	}
william's avatar
william committed
	// Update is called once per frame
	private void Update()
	{
		if (controller.hasStamina(energyCost) && controller.getCrossOverInput() == 1)
		{
			if (controller.isMyturn() && !controller.isSkillUsing() && !usingAxis)
			{
				StopCoroutine("move");
				animatorController.SetTrigger("CrossOver");
				consumeEnergy(energyCost);
			}
			usingAxis = true;
		} else
		{
			usingAxis = false;
		}
	}
william's avatar
william committed
	private IEnumerator crossOver()
	{
		controller.updateMovementLockStates();
		while (isActive)
		{
			rb.velocity = new Vector2 (-1, controller.currentHand) * controller.getSpeed() * speedModifier;
			yield return null;
		}
		controller.updateMovementLockStates();
	}

	private void updateState()
	{
		isActive = isActive == true ? false : true;
		StartCoroutine(crossOver());
	}

	public virtual void OnDisable()
	{
		CrossOverBehaviour.action -= updateState;
	}

	public virtual void OnEnable()
	{
		CrossOverBehaviour.action += updateState;
	}