我收到以下錯誤:我不斷收到錯誤CS0029
CS0029 Cannot implicitly convert type
UnityEngine.Renderer[]
toSystem.Collections.Generic.List<UnityEngine.Renderer>
的代碼是:
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
public class AssignShadersToChildren : MonoBehaviour
{
private new GameObject renderer;
public Shader shader; // This should hold the Shader you want to use
void Start()
{
// We create a list that will hold all the renderers(objects)
// so we can then assign the shader
List<Renderer> renderers = new List<Renderer>();
renderers = GetComponentsInChildren<Renderer>();
// For every Renderer in the list assign the materials shader to the shader
foreach (Renderer r in renderers)
{
r.material.shader = shader;
}
}
}
的方法'GetComponentsInChildren'可能是返回的'渲染[]''而不是名單' –
什麼是與錯誤的問題?你有錯誤的類型。你也創建一個扔掉的列表。將'renderers'的類型更改爲正確的類型並刪除創建的列表。 –