I was following a tutorial when I this error popped up and I don’t know how to fix it. Does anybody here know what the problem is and how to fix it?
Here is the link to the video, the code and the error message:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
public float playerSpeed;
private Rigidbody2D rb;
private Vector2 playerDirection;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
float directionY = Input.GetAxisRaw("Vertical");
playerDirection = new Vector2(0, directionY).normalized;
}
}
void FixedUpdate()
{
rb.velocity = new Vector2(0, playerDirection.y * playerSpeed);
}
Assets\Scripts\Scripts\Player.cs(24,5): error CS8803: Top-level statements must precede namespace and type declarations.