所以我想我在这里错过了一个图书馆。而不是“MeshRenderer”,我使用“MeshRenderer[]”来对条目数组进行字符串化。简而言之,我正在尝试将单独的图像上传到预制件的每个孩子。我收到以下错误消息。
using UnityEngine;
using UnityEditor;
using System.IO;
public class WallClick : MonoBehaviour
{
string path;
public MeshRenderer col;
public MeshRenderer[] boxCols;
void OnMouseDown()
{
boxCols = GetComponentsInChildren<MeshRenderer>();
path = EditorUtility.OpenFilePanel("Overwrite with png", "", "png");
GetImage();
}
void EnableChildComponents()
{
foreach (MeshRenderer col in boxCols)
{
col.enabled = true;
}
}
void GetImage()
{
if (path != null)
{
UpdateImage();
}
}
void UpdateImage()
{
byte[] imgByte = File.ReadAllBytes(path);
Texture2D texture = new Texture2D(2, 2);
texture.LoadImage(imgByte);
boxCols.material.mainTexture = texture; //Error here
}
}