- Home /
Can't Build PC Standalone due to multiple namespace script errors but playable in editor
My project works fine when played in the Unity editor. However, when I try to build it for the PC, Mac, & Linux standalone, it fails to build and gives me multiple errors such as:
Assets/Scripts/Respawn.cs(4,19): error CS0234: The type or namespace name `SceneManagement' does not exist in the namespace `UnityEngine'. Are you missing an assembly reference?
Assets/Scripts/CameraMovement.cs(5,31): error CS0246: The type or namespace name `MonoBehaviour' could not be found. Are you missing an assembly reference?
Assets/Scripts/PlayerCharacter/HERO/HeroMovement.cs(40,16): error CS0246: The type or namespace name `Vector2' could not be found. Are you missing an assembly reference?
and ends with
Error building Player because scripts had compiler errors
I have checked my scripts and none seem to be using the UnityEditor specific functions.
I am using Unity 5.6.1f1 Personal and there was a previous 4.6 installation when I updated to my current version (if that matters). I have also attempted a re-install of the current version by uninstalling and then re-installing the same version of Unity.
I have attached the editor log as well.
Any help would be greatly appreciated!
I might be wrong but I think this looks like the kind of error you get when the name of the script in the inspector does not match the name at the top in the actually code. did you try rena$$anonymous$$g any scripts recently?
This happens to me sometimes if I add a new script in Unity and then quickly switch to Visual Studio, before Unity finishes compilation (indicated by a rotating widget at the bottom right).
Then, Visual Studio gets filled with errors all over the place, because $$anonymous$$onoBehaviours etc are not recognized/found...
A quick fix I have found is to delete the new empty script, and recreate it, letting Unity finish its compilation after each step, i.e. rotating widget at the bottom right disappears. Then everything is back to normal.
I don't know if it's the same issue as the one you're having, but it looks quite similar.
Answer by DroidifyDevs · Jun 24, 2017 at 04:44 PM
For SceneManagement, you need to add "using UnityEngine.SceneManagement;" at the top of the script that's using SceneManagement.
Could you post CameraMovement and HeroMovement scripts?
For the Respawn script, I already have using the using UnityEngine.Scene$$anonymous$$anagement portion as seen here:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Scene$$anonymous$$anagement;
public class Respawn : $$anonymous$$onoBehaviour {
private GameObject player;
private bool Instance;
public static bool active = false;
void Update(){
player = GameObject.FindGameObjectWithTag("Player");
if (player != null) {
active = true;
}
if (player == null && active == true) {
Scene activescene = Scene$$anonymous$$anager.GetActiveScene ();
Scene$$anonymous$$anager.LoadScene (activescene.name);
}
}
}
Here is the script for Camera$$anonymous$$ovement:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Camera$$anonymous$$ovement : $$anonymous$$onoBehaviour
{
private GameObject player;
public float smoothTimeX = 0.05f;
public float smoothTimeY = 0.05f;
private Vector2 velocity;
private Vector2 zoompointnew;
private void FixedUpdate()
{
this.player = GameObject.FindGameObjectWithTag("Player");
if (!Input.Get$$anonymous$$ey($$anonymous$$eyCode.$$anonymous$$ouse1) && this.player != null)
{
Camera.main.orthographicSize = 15f;
float x = $$anonymous$$athf.SmoothDamp(base.transform.position.x, this.player.transform.position.x, ref this.velocity.x, this.smoothTimeX);
float num = $$anonymous$$athf.SmoothDamp(base.transform.position.y, this.player.transform.position.y, ref this.velocity.y, this.smoothTimeY);
base.transform.position = new Vector3(x, num + 0.5f, base.transform.position.z);
}
if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.$$anonymous$$ouse1) && this.player != null)
{
Camera.main.orthographicSize = 5f;
this.zoompointnew.x = Camera.main.ScreenToWorldPoint(Input.mousePosition).x;
this.zoompointnew.y = Camera.main.ScreenToWorldPoint(Input.mousePosition).y;
float x2 = $$anonymous$$athf.SmoothDamp(base.transform.position.x, this.zoompointnew.x, ref this.velocity.x, 2f * this.smoothTimeX);
float y = $$anonymous$$athf.SmoothDamp(base.transform.position.y, this.zoompointnew.y, ref this.velocity.y, 2f * this.smoothTimeY);
base.transform.position = new Vector3(x2, y, base.transform.position.z);
}
}
}
I have this nagging feeling that these problems are not with the scripts themselves but may be an error with my installation of Unity itself. Thank you for the reply!