Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by David Kim · Jul 18, 2011 at 06:39 PM · guiguitextfadeif

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;
 }

}

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image flaviusxvii · Jul 18, 2011 at 06:50 PM 0
Share

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.

avatar image flaviusxvii · Jul 18, 2011 at 06:52 PM 0
Share

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.

avatar image David Kim · Jul 18, 2011 at 07:11 PM 0
Share

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.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

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

Why is Unity registering my false boolean as true? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges