- Home /
UI Text In Seconds
public Text Damagew;
void Start () {
anim = GetComponent<Animator> ();
Damagew.enabled = false;
}
public void AppliedDamage(float damage){
health -= damage;
if (health <= 0f) {
anim.Play("Death");
Destroy (gameObject,2);
Damagew.enabled = true;
}
}
Answer by Arin_Jisoo · Sep 10, 2017 at 01:33 PM
This is my code. what i want to happen if. is the death animation play. the UI text shows with "Kill Zombie" and that's happen. but my problem is it not disappear what i want if after 1 seconds my text will be disappear and show up again when i kill another zombie. thanks for help :)
Answer by tormentoarmagedoom · Sep 10, 2017 at 04:57 PM
Hello @Arin_Jisoo !!
Then you need this:
Have a Text with " Zombie Kill ! " and use the "enabled" attribute to show/not show. You can also use the "Invoke" to send the command "stop showing the text in 1 second".
Lets call the Text Object TheTextYouWantToShow in the GameScene. Then, we need to declare and identify it in the script:
Text KillZmbText;
private void Start ()
{
KillZmbText = GameObject.Find ("TheTextYouWantToShow").GetComponent<Text>();
}
Now, lets create a method that will stop showing the text
void StopShowingZombieText()
{
KillZmbText.enabled=false;
}
Now we need to create the commands that will show the text, and will program for 1 second later the method "StopShowingZombieText". Put this in the script where will be executed when a zombie is killed:
KillZmbText.enabled=true;
Invoke ("StopShowingZombieText",1);
As you can imagine, the invoke calls a method writed as string (so is not possible to use methods with parameters) in a selected time (in float, you can use decimals like 1.5f or 8.256435f) :
Invoke ("Nameofmethod", time in seconds)
I think i solved your problem, if not, ask for more using @tormentoarmagedoom
Bye! :D
Text $$anonymous$$illZmbText;
void Start () {
anim = GetComponent<Animator> ();
$$anonymous$$illZmbText = GameObject.Find ("Zombie Hit!! + 5pts").GetComponent<Text> ();
}
void StopShowingZombieText(){
$$anonymous$$illZmbText.enabled = false;
}
public void AppliedDamage(float damage){
health -= damage;
if (health <= 0f) {
anim.Play("Death");
Destroy (gameObject,2);
$$anonymous$$illZmbText.enabled = true;
Invoke ("StopShowingZombieText", 1);
}
}
}
now its not showing up. but i don't get any error thank s for your time :)
$$anonymous$$aybe now you have some render problem. Try to dont use the "best Fit" text option, dont let the text ocuppy all the text box. Check the canvas render distances, layers, all this things.
You can check the iteracy to check if the text enables and disables.