- Home /
Disable and Enable UI text in function
so far this is my using code. what i want is. if i kill a zombie the word "zombie kill +5pts" will show up and disappear after 1 second. and appear again when i kill another zombie. like in Call Of Duty Multiplayer. any help and suggestion is accepted thanks. by the way this script is attached on zombie
Text KillZmbText;
void Start () {
anim = GetComponent<Animator> ();
KillZmbText = GameObject.Find ("Zombie Hit!! + 5pts").GetComponent<Text> ();
}
void StopShowingZombieText(){
KillZmbText.enabled = false;
}
public void AppliedDamage(float damage){
health -= damage;
if (health <= 0f) {
anim.Play("Death");
Destroy (gameObject,2);
KillZmbText.enabled = true;
Invoke ("StopShowingZombieText", 1);
}
}
}
Answer by PersianKiller · Sep 11, 2017 at 03:19 AM
it's very simple and easy idea :). you need a UI text
public void Zombie Hit(){
if(zombieDied){
StartCoroutine("aa");
}
}
public IEnumerator aa(){
t1.text="Zombie Hit!! + 5pts";
yield return new WaitForSeconds (1);
t1.text = "";
}
hope you get it :).
download this ,it might help
http://s8.picofile.com/file/8306100000/bandicam_2017_09_11_08_34_49_930.mp4.html
and then click on it to download ,it's not an English site and try not to sacre :D .
should i create UI text in my canvas ? thanks for your time
of course you should.then you can put your text when zombie died in there.
Well the text shows up from the beginning and its not disappearing after 1 seconds. maybe i am dumb. but i don't really get it haha. but i dont have errors
![SerializeField]private float health = 100f;
private Animator anim;
public Text t1;
void Start () {
anim = GetComponent<Animator> ();
}
public void AppliedDamage(float damage){
health -= damage;
if (health <= 0f) {
anim.Play("Death");
StartCoroutine ("a");
Destroy (gameObject,2);
}
}
public IEnumerator aa(){
t1.text = "Zombie Hit!! + 5pts";
yield return new WaitForSeconds(1);
t1.text = "";
}
}][1]
[1]: /storage/temp/101638-screenshot-48.png
@Arin_Jisoo I updated the answer check it.
Thank you Very much !! It works. but i have 1 more question i will put the IEnumerator in the AccessTheText Script so it will disappear after 1 seconds ? sorry for question but its not included in the Video xD