Wie die Verknüpfung einer GUI-Textur-Taste, um ein Skript in Unity3d

Ich brauche etwas Hilfe, um eine benutzerdefinierte GUI-Textur-Taste, starten Sie ein script auf ein 3d-Objekt aus, wenn es berührt wird in Unity3d für android.

Ich habe eine GUI-Schaltfläche und drehen Sie ein 3d-Modell auf gedrückt. Der folgende C# - Skript, die ich habe ist die Arbeit O. K., wenn der button erstellt wird progrmaticaly:

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;
        }

Möchte ich anstelle der Schaltfläche in den code und fügen Sie eigene benutzerdefinierte GUI Texture button (namens OrbitBtn), so auf touch, starten Sie das 3d-Modell drehen sich um Ihre axe.

Bitte, geben Sie mir einige Ratschläge wie Sie zu erreichen ist, die Funktionalität. Ich danke Ihnen allen im Voraus für Eure Antworten.

InformationsquelleAutor CodeBugging | 2014-03-21
Schreibe einen Kommentar