Hello:
I’ve been going through the tutorials for Unity and enjoy it so far, one issue I came across when trying to modify one of the projects to have an option to exit the game. I created a UI Text and placed it where I wanted, the problem came with the script.
When the “Q” button is pressed I want the Unity Editor to stop if I’m there and exit the application if I’m running stand alone, here’s my script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class QuitGame : MonoBehaviour {
void Update()
{
if (Input.GetKeyDown(KeyCode.Q))
{
FinishGame();
}
}
void FinishGame()
{
if (UnityEditor)
{
UnityEditor.EditorApplication.isPlaying = false;
}
else
{
Application.Quit();
}
}
}
When I compile it it give me the error “‘UnityEditor’ is a namespace but is used like a variable”. I’ve searched the help as well as Googled the hell out of it and I can’t find anything that solves the issue.
Relp?
Thanks!