我是靠谱客的博主 淡淡眼睛,这篇文章主要介绍unity运行时保存预制物,现在分享给大家,希望可以做个参考。

预制物体在运行是给子级添加物体后进行保存,下次运行添加的物体依然存在

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);
    }
    

}

将脚本挂在预制物体上,路径自己选择。

最后

以上就是淡淡眼睛最近收集整理的关于unity运行时保存预制物的全部内容,更多相关unity运行时保存预制物内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(114)

评论列表共有 0 条评论

立即
投稿
返回
顶部