- Home /
Problem is not reproducible or outdated
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?
if you're aksing for help with script errors, please include the script ;)
don't forget to format it using the 101/010 button
Cant believe i forgot to add my script, thanks for pointing that out!
Answer by phil_me_up · Jan 26, 2016 at 01:42 PM
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;
}
Wow, i completely forgot to add that, I feel so dumb! Thanks for the reply!