我有一张沙发的3D模型,其纹理要通过屏幕上显示的纹理更改按钮进行更改。如何通过Unity中的按钮更改纹理
例如。如果我触摸红色按钮,沙发颜色将变成红色;如果我触摸黑色按钮,沙发颜色将变黑。
目前,我可以通过触摸屏幕上的任何位置来更改沙发的纹理,但现在我想要触摸特定的按钮并根据按钮改变沙发纹理。
这里是我是我到目前为止有:
public class change_texture : MonoBehaviour {
public Texture[] texture;
public int currentTexture;
// Use this for initialization
void Start() {
Screen.orientation = ScreenOrientation.Landscape;
}
// Update is called once per frame
void Update() {
if (Input.touches[0].phase == TouchPhase.Began) {
currentTexture++;
currentTexture %= texture.Length;
GetComponent<Renderer>().material.mainTexture = texture [currentTexture];
}
}
}
我已经发布我的查询中后下,请审查并更新我! – Kushan2
你为什么在Update中运行?也无法防止出界? – Everts