Unity 有时候编辑的内容保存时提示如下信息:You must exit play mode to save the scene。
这是因为手动点暂停游戏后,画面状态并没有被关闭,而导致无法保存刚刚编辑的内容。
解决方案:
1.SampleScence下创建一个空白物体 Create empty。命名随意,比如esc4exit
2.为此空白物体创建一个脚本: add component->new script
3.代码块:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class exit : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//运行时按下esc,退出
if(Input.GetKey(KeyCode.Escape))
{
//先结束运行状态
UnityEditor.EditorApplication.isPlaying = false;
//再退出应用
Application.Quit();
}
}
}