【发布时间】:2014-04-29 12:51:21
【问题描述】:
我需要一些帮助来制作自定义 GUI 纹理按钮,在 Unity3d for android 中触摸 3d 对象时启动脚本。
我有一个 GUI 按钮可以在按下时旋转 3d 模型。我得到的以下(C#)脚本工作正常。以编程方式创建按钮时:
using UnityEngine;
using System.Collections;
public class RotateButtonBheaviour : MonoBehaviour {
private bool mIsRotated = false;
private bool mMustRotate = false;
private GameObject Cube;
// Use this for initialization
void Start () {
Cube = GameObject.Find ("MarkerObject");
}
// Update is called once per frame
void Update () {
if (mMustRotate && !mIsRotated) {
//Rotate all models 45 degrees around X
if (Cube != null) {
GameObject modelUnderChipsTrackable = Cube.transform.GetChild(0).gameObject;
modelUnderChipsTrackable.transform.RotateAround(new Vector3(1,0,0), Mathf.PI/3);
}
mIsRotated = true;
mMustRotate = false;
}
public Texture btnTexture1;
void OnGUI() {
if (!btnTexture1) {
Debug.LogError("Please assign a texture on the inspector");
return;
}
if (GUI.Button(new Rect(10, 10, 120, 30), btnTexture1))
if (!mIsRotated) {
mMustRotate = true;
}
我想代替代码中的按钮来添加我的自定义 GUI 纹理按钮(名为 OrbitBtn),等等触摸,以启动 3d 模型围绕其轴旋转。
请给我一些关于如何实现该功能的建议。提前感谢大家的回答。
【问题讨论】:
标签: c# android user-interface unity3d