Log in or register to post comments

GUI Button

April 26, 2014 - 6:05am #1
Hello everyone, I made this script, but it works only in part, when the target is detected the buttons appear, so everything is ok, but when I press the buttons to start the animations do not work, if I put a statement like "openurl "works, while the statement" animation.Play no!. did not understand where I'm wrong. Sorry for English 
 
Thank you so much 
 
Alessio
 
using UnityEngine;
using System.Collections;
 
public class bottoni : MonoBehaviour, ITrackableEventHandler {  
 
private TrackableBehaviour mTrackableBehaviour;
     
    private bool mShowGUIButton = false;
        
    void Start () {
        mTrackableBehaviour = GetComponent<TrackableBehaviour>();
        if (mTrackableBehaviour)
        {
            mTrackableBehaviour.RegisterTrackableEventHandler(this);
        }
    }
     
    public void OnTrackableStateChanged(
                                    TrackableBehaviour.Status previousStatus,
                                    TrackableBehaviour.Status newStatus)
    {
        if (newStatus == TrackableBehaviour.Status.DETECTED ||
            newStatus == TrackableBehaviour.Status.TRACKED)
        {
            mShowGUIButton = true;
        }
        else
        {
            mShowGUIButton = false;
        }
    }
 
void OnGUI () 
{
        if (mShowGUIButton) {
 
 
if (GUI.Button (new Rect (10,10,110,50), "cella")) {
animation.Play("cella");
 
}
if (GUI.Button (new Rect (10,70,110,50), "orologio")) {
animation.Play("orologio");
       
}
if (GUI.Button (new Rect (10,130,110,50), "portale")) {
animation.Play("portale");
            
}
if (GUI.Button (new Rect (10,190,110,50), "EXIT")) {
Application.Quit();
}
 
 
}
 
}
 
}

 

GUI Button

May 8, 2014 - 7:05am #3

Hi Alexv,

 

Thank you, for help me, i use your script for see when i click button in console windows write Playng OK.!!

When i click button "cella" console windows print "Playng OK", but my animation don't start.

Sigh !!

Alessio

GUI Button

May 1, 2014 - 4:41am #2

are you attaching this script to a gameObject that actually has a Animation module?

why don't you try:

if (GUI.Button (new Rect (10,10,110,50), "cella")) {
  if ( animation.Play("cella") ) {
      Debug.Log("Playing OK");
  } else {
     Debug.Log("Can't play cella");
  }
}

now play it, and see if there's a "Playing OK"  or "Can't play cella" message in the Console.

 
Log in or register to post comments