Your console shows three errors but there ought to be more above “error building player because scripts had compiler errors” because those compile errors will show up in the console too. Those are the ones you need to show / fix. And please post them as text.
The complete error message contains everything you need to know to fix the error yourself.
The important parts of the error message are:
the description of the error itself (google this; you are NEVER the first one!)
the file it occurred in (critical!)
the line number and character position (the two numbers in parentheses)
also possibly useful is the stack trace (all the lines of text in the lower console window)
Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.
Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly? Are you structuring the syntax correctly? Look for examples!
All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.
You may only use UnityEditor namespace methods and classes while you are in the Unity editor.
You may never use anything from the UnityEditor namespace in a build.
You can fix this in one of two ways:
wrap these bits of editor code in #if UNITY_EDITOR conditional compilation directives
you can put the entire script into a folder called Editor. This makes it what is loosely called an “editor script.”
Such “editor scripts” can NEVER be attached to GameObjects, either in prefabs or scenes.
The last thing i added before this happened is the “using UnityEditor;” code to make the select file dialog appear, is there some way to replace the unityeditor’s file picker with the other one?
Anything in the UnityEditor namespace is, as the name implies, only available in the editor. Generally any ‘Editor’ namespaces from Unity’s side or other packages is only for use in the editor. It can’t be used in a built project.
You can of course use the code for editor related things. Though you’ll need to ensure the code is in an Editor folder, or surrounded with #if UNITY_EDITOR pre-processors, or in an editor-only assembly definition.
For file select dialogues, you may need to look at the asset store for that.
I guess i should stop working on the level editor since it doesn’t even work.
Unless someone fixes it.
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class LevelDesignerPreview : MonoBehaviour
{
public bool isEditor;
public int scalex;
public int scaley;
public GameObject scalexinput;
public GameObject scaleyinput;
public string backgroundpath;
public GameObject background;
public SpriteRenderer backgroundspriteRenderer;
// Start is called before the first frame update
void Start()
{
if (isEditor == false)
{
string path = PlayerPrefs.GetString("designbackground");
if (!string.IsNullOrEmpty(path) && File.Exists(path))
{
// Background
Texture2D texture = new Texture2D(1, 1);
byte[] data = File.ReadAllBytes(path);
texture.LoadImage(data);
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
backgroundspriteRenderer.sprite = sprite;
// Adjustment
scalex = PlayerPrefs.GetInt("designbackgroundscalex");
scaley = PlayerPrefs.GetInt("designbackgroundscaley");
background.transform.localScale = new Vector3(scalex, scaley, 1.0f);
}
}
}
// Update is called once per frame
void Update()
{
}
public void TestDesign()
{
PlayerPrefs.SetInt("designbackgroundscalex", scalex);
PlayerPrefs.SetInt("designbackgroundscaley", scaley);
PlayerPrefs.SetString("designbackground",backgroundpath);
PlayerPrefs.Save();
}
public void OpenFileDialog()
{
string path = UnityEditor.EditorUtility.OpenFilePanel("Select Image", "", "png,jpg");
if (!string.IsNullOrEmpty(path) && File.Exists(path))
{
Texture2D texture = new Texture2D(1, 1);
byte[] data = File.ReadAllBytes(path);
texture.LoadImage(data);
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
backgroundspriteRenderer.sprite = sprite;
backgroundpath = path.ToString();
}
}
public void ScaleChanged()
{
scalex = int.Parse(scalexinput.GetComponent<InputField>().text);
scaley = int.Parse(scaleyinput.GetComponent<InputField>().text);
background.transform.localScale = new Vector3(scalex, scaley, 1.0f);
}
}
You’re still referencing UnityEditor. You can’t do that in a build. So this isn’t a “fix” situation as much as it’s a “rewrite” using an alternative approach.