【问题标题】:Unity C# Adding Material Component to new GameObjectUnity C#将材质组件添加到新的游戏对象
【发布时间】:2021-02-14 01:16:58
【问题描述】:

我在将 Material 组件添加到我的新游戏对象时遇到问题。

情况:我有一个大立方体和一颗子弹。子弹触及大立方体后。大立方体将拼成 5x5x5。还行吧。我为此创建了小立方体。我想为这些立方体添加颜色。我知道 blabla.AddComponent(); blabla.GetComponent().xxx;

我使用这种方法来添加刚体,但我无法添加材质。

我的代码:

piece.AddComponent();

piece.GetComponent().color = Color.red;

你能说我如何添加材料吗?

【问题讨论】:

    标签: c# unity3d game-development


    【解决方案1】:

    你不能,因为Material 不是Component

    相反,请执行以下操作:

    var mr = GetComponent<MeshRenderer>();
    mr.material = your material
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-09
      • 2017-05-11
      相关资源
      最近更新 更多