我画了很多不同颜色的盒子。为此,我使用MaterialPropertyBlocks
public override void DrawPlot()
{
for (int posIdx = 0; posIdx < data.Length; posIdx++)
{
plotModelInstances[posIdx] = GameObject.Instantiate(plotModel, ...);
_propBlock = new MaterialPropertyBlock();
_renderer = plotModelInstances[posIdx].GetComponent<Renderer>();
_renderer.GetPropertyBlock(_propBlock);
_propBlock.SetColor("Color", MiscUtils.GetColor(data[posIdx].Value / maxValue, StaticValues.jet));
_renderer.SetPropertyBlock(_propBlock);
}
}此函数是(非Monobehaviour)类的一部分。问题是,如果我运行这个程序,所有的块都是白色的。这是因为我在MonoBehaviour脚本之外使用了MaterialPropertyBlocks吗?
发布于 2020-09-08 16:52:54
找到问题了:该属性名为"_Color“,而不是”颜色“。
_propBlock.SetColor("_Color", MiscUtils.GetColor(data[posIdx].Value / maxValue, StaticValues.jet));
currentBar.GetComponent<MeshRenderer>().SetPropertyBlock(_propBlock);https://stackoverflow.com/questions/63789905
复制相似问题