- Home /
The type or namespace 'Unity Engine' could not be found
I get this error whenever creating the script through unity while making a game but if i create a project in MonoDev then the program works. I just reinstalled unity also so it doesn't seem to be able to be fixed by reinstalling and i need to create a lot of scripts through the game so i would like a solid solution to fix this
This happens with just a blank template or for part of the script i am trying to do. using UnityEngine;//error using System.Collections;
public class PlayerController1 : $$anonymous$$onoBehaviour {//error
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
or for the one that should move the ship in space shooter and i am using the updated guide through unity since this was made in and earlier version
using UnityEngine;//error "UnityEngine" using System.Collections;
public class PlayerController : $$anonymous$$onoBehaviour //error "$$anonymous$$onoBehaviour" { private Rigidbody rb;//error "rigidbody" public float speed;
void Start ()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
}
}
Next time tell us where you get that error. Errors inside your script editor are pointless. The only thing that is important if Unity complains when it compiles the script inside the Unity editor. If there's no error in Unity, it's a problem of your script editor.
And of course, if you just open a single script file in any text editor, that editor has no idea where this script belongs to. That's why there's a solution file in your project folder. When you open a script inside Unity, Unity actually opens the solution in the linked editor. The solution / project file contains information about all scripts that belong to the project as well as referenced assemblies.
Answer by TBruce · Oct 16, 2016 at 11:11 PM
I just took your code (with remarks removed) and received no errors. (see below)
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
private Rigidbody rb;
public float speed;
void Start ()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
}
}
I would suggest removing all references to he file in Unity, the close and re-open Unity and add the code above or use this file PlayerController.cs (unzip it first).
If you are still having problems then remove all references to PlayerController, close Unity, delete the folder Library
in you project folder. When you reopen Unity the Library
will be recreated.
I am still getting the same errors do you think it could be in the installation somehow i reinstalled unity and i checked everything so i could build it for whatever i need and i didnt uncheck anything but i still get errors for UnityEngine https://gyazo.com/cfc4908081f4743ff64b2953d9aaea8c here is an exact picture of the scrip you posted and i ran it immediately after opening it
What OS and version are you using? You should not have to do this but did you reboot after installing Unity?
windows 10 pro the latest version 5.4.2f1 but i have not rebooted ill try that after restart same errors
Answer by tanoshimi · Oct 16, 2016 at 09:34 PM
Looks like you've got an erroneous space there - the namespace is "UnityEngine", not "Unity Engine".
i do not see where your saying the space is it is written UnityEngine but if for some reason it isnt in what your seeing my code in $$anonymous$$onoDev does in fact have no space in it it it written using UnityEngine;
The title of you thread in fact has a space. Regardless, if your actual scripts have it right, it's something else that's causing the error.
namespaces can't contain spaces. So this error can never happen ^^. Ins$$anonymous$$d you would get something like "; expected".
So we've proved that the error, as stated in the question, can never happen. Problem solved ;)
Answer by ElijahShadbolt · Oct 16, 2016 at 10:47 PM
Whenever your script uses stuff from Unity like MonoBehaviour, Vector3, etc, you need to make sure that at the top of the file you include the line
using UnityEngine;
For example:
ExampleClass.cs
using UnityEngine;
public class ExampleClass : MonoBehaviour {
public Vector3 exampleVector;
void Start() {
Debug.Log(exampleVector);
}
}
Edit: I just looked at the above comments, so I'm not sure how helpful this answer would be.
That is what i have but and that is where the error is being generated when i copied here it posted here but if you go just above the code section you should see it say
using UnityEngine; and that is where the error is co$$anonymous$$g from it says exactly, "The type or namespace name 'UnityEngine' could not be found (are you missing a using directive or an assembly reference?)" Ive even looked into trying to add it manually but i cant seem to do it.
Your answer
![](https://koobas.hobune.stream/wayback/20220612094748im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Does LibSpotify SDK crashes Unity3D? 2 Answers
Linux server .so files not loaded 0 Answers