Legenda.cs 915 Bytes
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Legenda : MonoBehaviour {

	public Text LEGENDA;
	GameObject ICARO;
	Animation COMPONENTE_ANIMADOR;

	void Start () {

		ICARO = GameObject.FindGameObjectWithTag("avatar");
		COMPONENTE_ANIMADOR = ICARO.GetComponent<Animation>();

		LEGENDA = gameObject.GetComponent<Text>();


	}

	void Update(){

		if(COMPONENTE_ANIMADOR.isPlaying)
			LEGENDA.text = GetCurrentPlayingAnimationClip( );

	}

	string GetCurrentPlayingAnimationClip( ){
			
		foreach( AnimationState anim in COMPONENTE_ANIMADOR )
			if( COMPONENTE_ANIMADOR.IsPlaying( anim.name ) )
				if( !(anim.name.Split(' ')[0].Equals("_default")) )
					return anim.name.Split(' ')[0];

		return null;
		
	}

	bool isCaptionActiveFlag = true;
	public void ativarLegenda( ){

		isCaptionActiveFlag = !isCaptionActiveFlag;
		this.gameObject.SetActive(isCaptionActiveFlag);

	}

}