预制物体在运行是给子级添加物体后进行保存,下次运行添加的物体依然存在
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class savePrefab : MonoBehaviour
{
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.A))
{
Go();
}
}
void Go()
{
string localPath = "Assets/Resources/prefab/" + this.gameObject.name + ".prefab";
PrefabUtility.SaveAsPrefabAsset(this.gameObject, localPath);
}
}
将脚本挂在预制物体上,路径自己选择。