Why does this extremely simple script return an error?

I am beginning to try and learn programming and someone suggested i use this code so that an animation plays when i make my character run. It returns this single error in unity: “Assets/Scripts/Run.cs(1,10): error CS0116: A namespace can only contain types and namespace declarations” - How can i fix this?

As gjf said, please include your script when asking these questions.

However, my guess based on the error message (indicating the error is on line 1) is that you’re doing something like this:

int test = 0;
using UnityEngine;
using System.Collections.Generic;

public class MyClass : MonoBehaviour 
{
}

Note that you are declaring an int outside of the class which is not permitted. Instead do this:

using UnityEngine;
using System.Collections.Generic;
    
public class MyClass : MonoBehaviour 
{
    int test = 0;
}