- Home /
Display GUI when kill count reaches 5
Ok so I have this kill counter script it works fine and all but the fade part is not working. I got the fade code from the unity wiki site. It compiles and everything but when i test drive it like after I get 5 kills it wont show the warning message on the screen. If i get rid of the if statement if(kills==5) i see the message show up when i start up the game. But I want it to show up after the user kills 5 of the enemies. Again everything compiles with no bugs just that the message does not show up when i kill 5..
var guiSkin : GUISkin = null;
var kills: int = 0;
var warning : AudioClip;
function OnGUI() {
GUI.skin = guiSkin;
GUI.Label(new Rect(10, 60, 100, 30), "KILLS:");
GUI.Label(new Rect(110, 60, 150, 30), kills.ToString());
GUI.skin = null;
}
function Start () {
if(kills==5){
guiText.text = "Warning!";
audio.PlayOneShot(warning);
var colors = [Color.red, Color.yellow];
for (i = 0; i < 3; i++) {
yield Fade.use.Colors(guiText.material, colors, 1.5, false);
}
yield WaitForSeconds(2);
guiText.text=null;
}
}
Take some time and make sure your code is formatted. You'll encounter rage for posting messy code.
I don't see you ever incrementing kills, so how is it ever supposed to reach 5?.. Add some print statements (Debug.Log) and make sure everything you think is happening is actually happening.
Also, your title and tags are terrible. People looking for general "help me debug" and "write my code" 'questions' don't get much help. Narrow down your question to a single answerable idea.
ooo i have another script that increments it and sends it to this script i see its incrementing on the game cause the kills are going up from 1 to 5. Just that when it reaches 5 it wont send out the warning message. But if i put the if statement in the function gui it prints out the warning message when i get 5 kills but it wont do the fade.
Answer by David Kim · Jul 18, 2011 at 07:16 PM
var kills : int = 1;
function OnDestroy()
{
var tempobj : GameObject = GameObject.FindWithTag("killscore");
var countScript : killcounttest = tempobj.GetComponent(killcounttest);
countScript.kills+=kills;
}
so this is the code thats on my zombie so that everytime it dies it gets added to the killscore gui. It works perfectly fine by i just dont know why if(kills==5) wont work. I mean it compiles just wont print. But if i put it on the function OnGUI it pritns after i get 5 kills just that it wont do the fade effect then.
Your answer
Follow this Question
Related Questions
Gui Pop-Up Notification for Picking up Items 1 Answer
Fix Blurry UI text? 10 Answers
FadeIn/FadeOut the GUI 2 Answers
Set name for game 0 Answers