peanutbutterguy
peanutbutterguy

Reputation: 11

Hello I keep getting the error "return type must be 'void' to match overridden member" and I can't seem to fix it

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

Answers (1)

Simon
Simon

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

Related Questions