Hi guys i have a problem, i was making my level editor when i got this error
PlayerLoop called recursively!
UnityEditor.EditorApplication:NewScene()
LevelEditor:OnGUI() (at Assets/LevelEditor.cs:24)
this is the code
using UnityEngine;
using System.Collections;
using UnityEditor;
public class LevelEditor : MonoBehaviour {
bool NewLev=false;
string LevelName="";
// Use this for initialization
void Start () {
DontDestroyOnLoad(this);
}
// Update is called once per frame
void Update () {
}
void OnGUI(){
if(GUI.Button(new Rect(0,0,80,30),"New Level")){
NewLev=true;
}
if(NewLev){
GUI.Box(new Rect(Screen.width/2-80,Screen.height/2-50,180,100),"New Level");
GUI.Label(new Rect(Screen.width/2-75,Screen.height/2-10,90,20),"Level Name");
LevelName = GUI.TextField(new Rect(Screen.width/2,Screen.height/2-10,90,20),LevelName);
if(GUI.Button(new Rect(Screen.width/2-15,Screen.height/2+15,60,30),"Create")){
UnityEditor.EditorApplication.NewScene();
UnityEditor.EditorApplication.SaveScene(LevelName,true);
}
}
}
OnGUI gets called a couple of times per Update sometimes.
Set a boolean in the second button (Create), and check that boolean in your normal Update code instead.
that’s the new code but i have the same error
using UnityEditor;
public class LevelEditor : MonoBehaviour {
bool NewLev=false;
bool Create=false;
string LevelName="";
// Use this for initialization
void Start () {
DontDestroyOnLoad(this);
}
// Update is called once per frame
void Update () {
if(Create){
UnityEditor.EditorApplication.NewScene();
UnityEditor.EditorApplication.SaveScene(LevelName,true);
NewLev=false;
LevelName="";
Create=false;
}
}
void OnGUI(){
if(GUI.Button(new Rect(0,0,80,30),"New Level")){
NewLev=true;
}
if(NewLev){
GUI.Box(new Rect(Screen.width/2-80,Screen.height/2-50,180,100),"New Level");
GUI.Label(new Rect(Screen.width/2-75,Screen.height/2-10,90,20),"Level Name");
LevelName = GUI.TextField(new Rect(Screen.width/2,Screen.height/2-10,90,20),LevelName);
if(GUI.Button(new Rect(Screen.width/2-50,Screen.height/2+15,60,30),"Create")){
Create=true;
}
if(GUI.Button(new Rect(Screen.width/2+15,Screen.height/2+15,60,30),"Cancel")){
NewLev=false;
LevelName="";
}
}
}
}
What if you set the bool first?
if (Create)
{
Create = false;
//Blah Blah other code
}
same think same error i dont know what the fuck is the error