using UnityEngine; using UnityEngine.UI; using System.Collections; public class tchat_anim : MonoBehaviour { public Text chat; public Animator machine; public Text charac_nb; public InputField myfield; public Text timer; float timer_sec; int max_timer; // Use this for initialization void Start () { timer_sec = 0; max_timer = 15; } void Awake(){ } // Update is called once per frame void Update () { print (machine.GetInteger("etat_chat")); //transition vers chat_up if (myfield.textComponent.cachedTextGenerator.lineCount > 1 && machine.GetInteger("etat_chat")==0) { print ("trop long"); machine.SetInteger ("etat_chat", 1); charac_nb.text = " "; } //transition vers chat_long if (chat.text.Length > 110 && machine.GetInteger("etat_chat")==1) { print ("trop trop long"); machine.SetInteger ("etat_chat", 2); } //affichage nombre de caractère restant. if(Input.anyKey && machine.GetInteger("etat_chat")==2 ){ charac_nb.text = (myfield.characterLimit - myfield.text.Length).ToString(); } //transition vers chat_empty: si l'on vide complètement un message, le tcht se rabaisse. //sinon on le laisse haut (y compris si le message est court). if ((machine.GetInteger ("etat_chat") == 1 || machine.GetInteger ("etat_chat") == 2) && myfield.text.Length == 0 ) { machine.SetInteger ("etat_chat", 0); } //En cas de validation du message if(Input.GetKeyDown("space") && myfield.isFocused){ myfield.text=""; charac_nb.text=""; print ("space pressed"); //texte long if(machine.GetInteger("etat_chat")==1 || machine.GetInteger("etat_chat")==2){ machine.SetInteger ("etat_chat", 3); } //texte court if(machine.GetInteger("etat_chat")==0){ machine.SetInteger("etat_chat",3); } } //Gestion de l'état Timer. if (machine.GetInteger ("etat_chat") == 3) { timer_sec += Time.deltaTime; timer.text = (max_timer - (int) timer_sec ).ToString() + " secondes restantes"; if(timer_sec >= (float)max_timer-1){ timer_sec=0; timer.text=""; machine.SetInteger ("etat_chat", 0); } } } }