在运行时更改增强对象(AR Core)的颜色

时间:2019-09-27 05:30:03

标签: c# android unity3d arcore

我正在使用AR Core SDK中的“图像目标检测”示例。我想在运行时通过脚本更改对象的颜色。材质已附加到该对象。

<field name = 'status' widget="selection" decoration-danger="status=='open'" decoration-info="status=='pending'" decoration-muted="status=='solved'"/>

这是我当前的代码,在从不同答案中得到提示后,我试图实现该代码,但似乎无济于事。

1 个答案:

答案 0 :(得分:1)

我可以通过创建具有相应颜色的材质并为AR对象提供这种类型的组件来做到这一点(显然,您需要在检查器中将引用分配给renderercolorMaterial ):

using UnityEngine;

public class ARObjectController : MonoBehaviour
{
    public Renderer renderer;
    public Material colorMaterial;

    public SetMaterial()
    {
        renderer.material = colorMaterial;
    }
}