Hello Guys:
I’m currently writing a game manager that allows the user to Edit some basic status of a character before add it to the scene, I’m using the following script to create characters right now:
public class AddCharacter : EditorWindow
{
GameObject obj = null;
GameObject tempobj = null;
Vector3 vec3 = new Vector3(0, 0, 0);
CharacterClass classname = null;
string objname = "";
[MenuItem("Asset/TestCreate")]
public static void ShowWindow()
{
var window = GetWindow<AddCharacter>();
window.title = "Create Character";
}
public void OnGUI()
{
EditorGUILayout.BeginVertical();
obj = EditorGUILayout.ObjectField("Select game object to place", obj, typeof(GameObject), true) as GameObject;
vec3 = EditorGUILayout.Vector3Field("placement position:", vec3);
objname = EditorGUILayout.TextField("Name for new Character: ", objname);
if (obj && objname != "")
{
if (GUILayout.Button("Add to scene"))
{
tempobj = (GameObject)Instantiate(obj, vec3, Quaternion.identity);
tempobj.name = objname;
Characters temp = tempobj.GetComponent<Characters>();
CharacterClass selectedclass = AIManager.Instance.GetNewCharInfo();
temp.SetName(objname);
temp.SetClass(selectedclass);
temp.UpdateCharacter();
selectedclass.AddCharacters(objname);
AIManager.Instance.setnewChar(true);
AIManager.Instance.CreateCharacters(objname);
Close();
}
}
else
{
EditorGUILayout.LabelField("You must select an object and give it a name first");
}
EditorGUILayout.EndVertical();
}
}
However, I found that everything I created by using this script would disappear when I reopen the project, so is there a way to keep those changes( Add or delete game objects by script) in Unity?