0

I'm working with Unity and Microsoft Visual Studio. I'm new to coding and I keep getting this error:

player.start() is marked as override but no suitable method found to override

Code:

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



/// <summary>
/// This is the player script, it contains functionality that is specific to the player
/// </summary>
public class Player : Character
{
    [SerializeField]
    private Stat health;

    [SerializeField]
    private Stat mana;

    private float initHealth = 100;

    private float initMana = 50;

    protected override void Start()
    {

        health.Initialize(initHealth, initHealth);
        mana.Initialize(initMana, initMana);

        base.Start();
    }

    /// <summary>
    /// We are overriding the characters update function, so that we can execute our own functions
    /// </summary>
   protected override void Update ()
    {
        //Executes the GetInput function
        GetInput();

        base.Update();
    }

    /// <summary>
    /// Listen's to the players input
    /// </summary>
    private void GetInput()
    {
        direction = Vector2.zero;

        ///THIS IS USED FOR DEBUGGING ONLY
        ///
        if (Input.GetKeyDown(KeyCode.I))
        {
            health.MyCurrentValue -= 10;
            mana.MyCurrentValue -= 10;
        }
        if (Input.GetKeyDown(KeyCode.O))
        {
            health.MyCurrentValue += 10;
            mana.MyCurrentValue += 10;
        }

        if (Input.GetKey(KeyCode.W))
        {
            direction += Vector2.up;
        }
        if (Input.GetKey(KeyCode.A))
        {
            direction += Vector2.left;
        }
        if (Input.GetKey(KeyCode.S))
        {
            direction += Vector2.down;
        }
        if (Input.GetKey(KeyCode.D))
        {
            direction += Vector2.right;
        }
    }
}
halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

0

Ensure that your Character class have a virtual method named Start

fruggiero
  • 943
  • 12
  • 20
  • How can i be sure of that im new to this stuff can you show a screenshot maybe? – Ximithie Graal Nov 13 '17 at 01:04
  • Simply go to your character class and see if there is a `virtual void Start()` method. – fruggiero Nov 13 '17 at 01:42
  • Like i said im new just tell me whats wrong with the code or show screenshot – Ximithie Graal Nov 13 '17 at 18:32
  • @XimithieGraal - find the file in your project that contains the `Character` class (it will probably contain the line `public class Character`). Look through it for a method called `Start()`, and if it exists, ensure it's marked as `virtual void`. If it doesn't exist, then you can't `override` it. – Adam V Nov 13 '17 at 20:19
  • @XimithieGraal Right click on `Character` on this line : `public class Player : Character` and then "go to definition". Visual Studio will bring you to the definition of the Character class. Here you can check for the existance of the Start method, which must be marked as Virtual otherwise can't be overridden – fruggiero Nov 13 '17 at 23:16
  • It say's cannot navigate to the symbol under the caret – Ximithie Graal Nov 14 '17 at 00:10
  • @XimithieGraal check if you are affected by this: https://stackoverflow.com/questions/33029127/go-to-definition-cannot-navigate-to-the-symbol-under-the-caret – fruggiero Nov 20 '17 at 14:50