Andere
How to save as prefab when a button is pressed
Hello, I found this Thread but I did not found a good answer. I would like to create a button and if this button is pressed it should save the 2D created Character (<- 'Character' is an Empty GameObject with child Objects attached on it, like 'Arms', 'Legs', etc. and those have a spriteRenderer on them to select the different sprites) with all of its child objects as a prefab.
I have something like this:
public void SaveCharacterAsPrefab()
{
Transform.Instantiate Character
int Character
string prefabPath = "SavedCharacters";
PrefabUtility.CreatePrefab("Assets/Resources/" + prefabPath + "/" + Character.name + ".prefab", Character, ReplacePrefabOptions.ReplaceNameBased);
}
But (of course) it doesn't work because I don't know exactly how to 'tell the script' that it should save the Character with all of its child objects and (for example) name/save it as 'Character 1'. I don't know how I can solve it... Thanks for anyone who wants to help!
Answer by OctoMan · Nov 09, 2015 at 11:50 AM
Read this, it might help you out. http://prof.johnpile.com/2014/07/27/generateprefab/
Well, it's good but I cannot do a working script for my project on my own. I just don't know how to change/add things to some of those scripts so it's working for me, too... :(