So i got this error: Assets\Player\Player.cs(27,14): error CS0116: A namespace cannot directly contain members such as fields or methods
And all i know about this error is that the lines of codes that are bad are 27 and 14
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
private bool jumpKeyWasPressed;
private float horizonalInput;
// Start is called before the first frame update
void Start()
{
}
void update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
jumpKeyWasPressed = true;
}
horizonalInput = Input.GetAxis("Horizontal");
}
}
private void FixedUpdate()
{
if (jumpKeyWasPressed)
{
GetComponent<Rigidbody>().AddForce(Vector3.up * 5, ForceMode.VelocityChange);
jumpKeyWasPressed = false;
}
GetComponent<Rigidbody>().velocity = new Vector3(horizontalInput, GetComponent<Rigidbody>().velocity.y, 0);
Close your FixedUpdate function with a } on line 36.
FixedUpdate is also outside of the class. This is what the error is referring to. You can’t put functions outside of a class. (27,14) refers to the 27th line and 14th character rather than two different lines.
To fix it, your class ends with the close curly brace } on line 25 . Move that down a bit, and put the whole of FixedUpdate before it.
Also, be careful of capitalisation. On line 17 update should be Update, or it won’t run unless you call it manually.