![](/img/trans.png)
[英]How do I load any file from assets folder with extension(.json) in C# Unity
[英]How to load a material file in Unity which is outside Assets folder?
我有一架飛機,我想在運行時動態加載其材料。 上述材料在 Unity 項目文件夾之外。 如何在我的游戲中加載它?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Experiment : MonoBehaviour
{
public Material materialToChange;
Material m_Material;
void Start()
{
m_Material = GetComponent<Renderer>().material;
}
void Update()
{
if(Input.GetKeyDown("a"))
{
GetComponent<Renderer>().material=materialToChange;
}
}
}
所以在這里我希望 materialToChange 是一個材質文件,我想給出它的路徑並且在 Unity Project 文件夾之外。
Unity 提供了允許在運行時加載資產(游戲對象、材質等)的 AssetBundle。 例如,目標是創建一個包含新材料的 AssetBundle。 然后您可以下載此 AssetBundle(從本地路徑或從 Web 下載)並提取您的資產。 您將能夠使用新材料更改您的材料!
看看這個頁面: Unity AssetBundles
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.