Search code examples
c#unity-game-engine2d

I was getting 3 errors when following a tutorial and I don't know how to fix them


These are my 3 errors that I have:

Assets/Scripts/Controllers/PlayerController.cs(13,27): error CS0115: 'PlayerController.RetrieveMoveInput()': no suitable method found to override

Assets/Scripts/Controllers/PlayerController.cs(8,26): error CS0115: 'PlayerController.RetrieveJumpInput()': no suitable method found to override

Assets/Scripts/Controllers/PlayerController.cs(6,33): error CS0246: The type or namespace name 'InputController' could not be found (are you missing a using directive or an assembly reference?)

This was the video I was watching: https://www.youtube.com/watch?v=lcw6nuc2uaU&t=140s

These are my 2 scripts:

InputController:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public abstract class Input : ScriptableObject
{
    public abstract float RetrieveMoveInput();
    public abstract bool RetrieveJumpInput();
}

PlayerController:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(fileName = "PlayerController", menuName = "InputController/PlayerController")]
public class PlayerController : InputController
{
    public override bool RetrieveJumpInput()
    {
        return Input.GetButtonDown("Jump");
    }

    public override float RetrieveMoveInput()
    {
        return Input.GetAxisRaw("Horizontal");
    }

}

Sorry if I've not formatted this correctly, haven't been on here in so long!


Solution

  • You've made a typo depending on how you want to view it should be either:

    //wrong class declaration
     public abstract class Input : ScriptableObject
    {...}
    //correct class declaration (how it is written in the github of the tutorial)
     public abstract class InputController : ScriptableObject
    {...}
    

    alternatively you could also do

    //corrected class declaration in other script
    public class PlayerController : Input
    

    However I would advise against that and use the tutorial variant, because Input is already a default Unity class that is used for input devices and you'll just be confusing yourself and the compiler.