I have a coroutine which I'm trying to make a dash script from (using the unity New Input System & standard unity CharacterController) and calling the Coroutine in the scriptable object makes unity seize up.
If I were to put the controller.Move() in Activate() it would work but blink instead of dash. I've tried to use a coroutine to avoid this, but I can't use coroutines in ScriptableObjects so instead I made a blank MonoBehaviour called MonoInstance (which you can see below). I use this solely to call the StartCoroutine function from.
This crashes Unity, now my head hurts. Help
Tl;Dr - Unity crash. How make not crash. Brain hurt.
Ability
public class Ability : ScriptableObject
{
public new string name;
public float cooldownTime;
public float activeTime;
public virtual void Activate(GameObject parent) { }
}
DashAbility
[CreateAssetMenu]
public class DashAbility : Ability
{
private PlayerController movement;
private CharacterController controller;
public float dashVelocity;
public override void Activate(GameObject parent)
{
movement = parent.GetComponent<PlayerController>();
controller = parent.GetComponent<CharacterController>();
MonoInstance.instance.StartCoroutine(Dashing());
}
IEnumerator Dashing()
{
float startTime = Time.time;
while(Time.time < startTime + activeTime)
{
controller.Move(movement.move.normalized * dashVelocity * Time.deltaTime);
}
yield return null;
}
}
MonoInstance
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MonoInstance : MonoBehaviour
{
public static MonoInstance instance;
private void Start()
{
MonoInstance.instance = this;
}
}