Reputation: 11
Here is my code. I keep getting the same error
and I can't seem to resolve it.
using System.Collections;
using UnityEngine;
namespace CreatingCharacters.Abilities
{
[RequireComponent(typeof(PlayerMovementController))]
public class genjidash : Ability
{
[SerializeField] private float dashForce;
[SerializeField] private float dashDuration;
private PlayerMovementController playerMovementController;
private void Awake()
{
playerMovementController = GetComponent<PlayerMovementController>();
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.LeftShift))
{
StartCoroutine(Cast());
}
}
public override IEnumerator Cast()
{
playerMovementController.AddForce(Camera.main.transform.forward, dashForce);
yield return new WaitForSeconds(dashDuration);
playerMovementController.ResetImpact()
}
}
}
Here is the code that it is parented to:
using UnityEngine;
namespace CreatingCharacters.Abilities
{
public abstract class Ability : MonoBehaviour
{
public abstract void Cast();
}
}
Any advise would be great and thank you in advance.
Upvotes: 0
Views: 1602
Reputation: 667
class genjidash
is derived from Ability
, the return of Cast()
in Ability
is void, but in genjidash
it's IEnumerator, so maybe you should change your base Cast()
to
public abstract class Ability : MonoBehaviour
{
public abstract IEnumerator Cast();
}
If you can't change Ability's Cast(), you need
private void Update()
{
if (Input.GetKeyDown(KeyCode.LeftShift))
{
StartCoroutine(CastAndReset());
}
}
private IEnumrator CastAndReset()
{
Cast();
yield return new WaitForSeconds(dashDuration);
playerMovementController.ResetImpact()
}
public override void Cast()
{
playerMovementController.AddForce(Camera.main.transform.forward, dashForce);
}
Upvotes: 3