I'm facing problem because of void awake which is causing this error "my code looks like this and having this problem "top-level statements must prec

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

public class InputManager : MonoBehaviour
{
private PlayerInput playerInput;
private PlayerInput.OnfootActions onfoot;
}
// Start is called before the first frame update
void Awake()
{
playerInput = new PlayerInput();
onfoot = playerInput.onfoot;

}

// Update is called once per frame
void Update()
{
 void OnEnable();  
}

{
onfoot.Enable();
}
{
onfoot.Disable();
}
{}

what is this ?? what are you hoping to achieve with this?

Next up are these? they dont appear to be inside any methods??

1 Like

Yeah, you’re just making typing mistakes. We can’t help you there.

You can fix your own typing mistakes. Here’s how:

Remember: NOBODY here memorizes error codes. That’s not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

The complete error message contains everything you need to know to fix the error yourself.

The important parts of the error message are:

  • the description of the error itself (google this; you are NEVER the first one!)
  • the file it occurred in (critical!)
  • the line number and character position (the two numbers in parentheses)
  • also possibly useful is the stack trace (all the lines of text in the lower console window)

Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly? Are you structuring the syntax correctly? Look for examples!

All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.

Two steps to tutorials and / or example code:

  1. do them perfectly, to the letter (zero typos, including punctuation and capitalization)
  2. stop and understand each step to understand what is going on.

If you go past anything that you don’t understand, then you’re just mimicking what you saw without actually learning, essentially wasting your own time. It’s only two steps. Don’t skip either step.

I’m going to make a guess that the text editor you are using is trying to be “helpful” by auto-completing some things. And you are not properly interacting with those auto-completions and try to manually complete your own code. If you look at the code you posted its not valid, there are too many curly brackets and semicolons and in the wrong places, and I assume you wanted to add an OnDisable method but its not included here.

The autocompletion is useful and a time-saver for people used to coding, but its off-putting to people trying to learn how to code. Try writing the class from scratch again but pay special attention to any extra code that’s added thru auto-completion by your editor to be “helpful”.