Compiler errors alle the time :(

Hi Guys,
I start to be a liitle bit frustrated as i receive very, very often “compiler errors”. I try to learn Unity myself by using online trainigs that is why sometimes i rewrite the code from the tutorial. A lot of times i can’t continue/progress because compiler errors appear even durin execution super simple scripts.

For example:
My script:

using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour
{
void Update()
{
if (Input.GetKey(“up”))
{
print(“up arrow key is held down”);
}
if (Input.GetKey(“down”))
{
print(“down arrow key is held down”);
}
}
}

OUTCOME:
The referenced script (ruch) on this Behaviour is missing!
The referenced script on this Behaviour (Game Object ‘Cube’) is missing!
Assets\Scenes\ruch.cs(4,14): error CS0101: The namespace ‘’ already contains a definition for ‘ExampleClass’
ssets\Scenes\ruch.cs(6,10): error CS0111: Type ‘ExampleClass’ already defines a member called ‘Update’ with the same parameter types

Win32Exception: The system cannot find the file specified.
System.Diagnostics.Process.StartWithShellExecuteEx (System.Diagnostics.ProcessStartInfo startInfo) (at <9f8c4786222746238eb929db40bf8dd1>:0)
System.Diagnostics.Process.Start () (at <9f8c4786222746238eb929db40bf8dd1>:0)
(wrapper remoting-invoke-with-check) System.Diagnostics.Process.Start()
UnityEditor.DefaultExternalCodeEditor.OpenProject (System.String path, System.Int32 line, System.Int32 column) (at C:/buildslave/unity/build/Editor/Mono/CodeEditor/DefaultExternalCodeEditor.cs:131)
Unity.CodeEditor.CodeEditor.OpenProject (System.String path, System.Int32 line, System.Int32 column) (at C:/buildslave/unity/build/Editor/Mono/CodeEditor/CodeEditor.cs:31)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

Three things for starters:

  • You can only have one ExampleClass in one namespace (if you don’t use namespaces, then in your project)
  • You always need to put your MonoBehaviours in a cs file with the same name as the class is, so ExampleClass always should be in a file named ExampleClass.cs
  • if and when you post code on the forum, use the CODE tags, so it can be readable Using code tags properly

Do this modifications and if you still have errors, please, post here again with the description of what’s happening.

1 Like