首页 > 编程语言 > 详细

Unity:You must exit play mode to save the scene问题解决

时间:2021-03-14 13:55:20      阅读:277      评论:0      收藏:0      [点我收藏+]

出现上述错误时,通常是处于游戏模式也就是play mode的状态下进行保存操作,此时无法完成保存指令。

通常遇到这个问题时已经进入游戏模式且没有添加退出功能,下面首先介绍一下游戏退出功能的实现:

我们通常习惯使用esc键退出应用,因此这里使用esc键触发退出游戏模式的事件。

首先添加一个空物体(Create empty),在空物体中添加component,新建一个script,打开编辑界面并输入以下代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class QuitGame : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKey(KeyCode.Escape))

            {
                UnityEditor.EditorApplication.isPlaying = false;

                //Application.Quit();

            } 
    }
}

其中

UnityEditor.EditorApplication.isPlaying = false;

是在Unity编辑项目的过程中使用的,在完成后我们使用:

Application.Quit();

对于还没有添加上述功能的情况下,本次进入游戏模式后的编辑内容都无法保存,需要关闭unity后重新打开项目并添加上述脚本后方能正常退出游戏模式。

Unity:You must exit play mode to save the scene问题解决

原文:https://www.cnblogs.com/btc1996/p/14532193.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!