Home>

I got this error.

  

Assets/localforders/script/roulettecontroller.cs (28,34): error CS0234: The type or namespace nameEditorUtility 'does not exist in the namespaceUnityEditor'. Are you missing an assembly reference ?

The code is

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class roulettecontroller: MonoBehaviour
{
    float rotspeed;
    // Use this for initialization
    void Start ()
    {
    }
    // Update is called once per frame
    void Update ()
    {
        if (Input.GetMouseButtonDown (0) || Input.GetKeyDown (KeyCode.Space))
        {
            this.rotspeed = Random.Range (50, 200);
        }
        transform.Rotate (0, 0, this.rotspeed);
        this.rotspeed * = Random.Range (0.96f, 0.98f);
        if (Input.GetKeyDown (KeyCode.Escape))
        {
            bool b = UnityEditor.EditorUtility.DisplayDialog ("Thank you for using", "Do I want to close the app?", "Yes", "No");
            if (b)
            {
                UnityEngine.Application.Quit ();
                UnityEditor.EditorApplication.isPlaying = false;
            }
            else
            {
            }
        }
    }
}


It's like this.
If i try to build, it looks like this,
I understand the meaning somehow, but I don't know how to solve it.

  • Answer # 1

    Things under the UnityEditor namespace basically work only on the editor.
    Cannot be used during build
    Please wrap the editor-only code with #if UNITY_EDITOR

  • Answer # 2

    using UnityEditor;