如何使用 AR 相机统一单击按钮在 运行 时间更改对象的纹理

How to change the texture of object at run time on button click in unity by using AR camera

我想使用 AR 相机在 运行 时间统一更改 3D 模型的纹理。
我使用主摄像头完成了这项工作,但使用 AR 摄像头却无法正常工作。
我将此脚本附加到一个多维数据集并创建一个按钮并在按钮的 onClick 函数中添加该多维数据集,并且通过使用 unity 主摄像头可以正常工作,但它不能与 AR Camera 一起使用。这是我的脚本:

using UnityEngine;using System.Collections;public class TexturesSwap : MonoBehaviour {
public Texture[] textures;
public int currentTexture;

void Start () {

}   
public void swapTexture() { currentTexture++;
    currentTexture %= textures.Length;
    GetComponent<Renderer>().material.mainTexture = textures[currentTexture]; 
}}

对于交换纹理,我有带有一些纹理的纹理文件夹,并且通过脚本我可以在使用主摄像头时更改对象的纹理,但是如何使用 AR 摄像头做同样的事情?请帮我。谢谢

这是我的错误

您需要为对象添加渲染器。为此..在资产中创建一个material(右键单击资产文件夹并单击material)。将此 material 附加到对象。然后在代码中设置纹理:

  transform.GetComponent<Renderer>().material.texture="yourTexture"