Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Mar 07, 2015 at 09:55 PM by KnightRiderGuy for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by KnightRiderGuy · Mar 03, 2015 at 10:34 PM · c#uidecreasetimersprogressbar

UI Decreasing Timer Bar Not Executing Print?

I have this UI timer bar that decreases in size only when it reaches the end it does not seem to print the "You Loose" statement. I'm missing something simple I'm sure but just not seeing it. I forgot to mention my Bar is just a UI image set to "Fill" from Left to Right" if that helps, the bar works and decreases the fill amount only it;s not doing the last part of the script right. I can find a way around getting the whole screen to do what I need with another timer function set to a certain time and then have it do what I need but that is more complicated than it needs to be when just this simple script should do the job.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine.UI;
 
 public class BarHandler : MonoBehaviour {
 
     public Image DeathTimerBar;
     public float DecreaseAmount;
 
     void Update (){
         DeathTimerBar.fillAmount -= DecreaseAmount * Time.deltaTime;
 
         if (DeathTimerBar.fillAmount >= 1f) {
             print ("You Loose!");
             this.enabled = false;
         }
     }
 }
Comment
Add comment · Show 1
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 Mmmpies · Mar 04, 2015 at 02:53 PM 0
Share

Well on my phone so I could have missed something but it looks O$$anonymous$$ to me why not print the value of your DeathTimerBar.fillAmount before the if as debug check.

1 Reply

  • Sort: 
avatar image
2
Best Answer

Answer by tigertrussell · Mar 04, 2015 at 02:54 PM

(edited to remove stupid question about print wrapper)

It looks like you're subtracting from fillAmount and then expect it to print when it is >= 1f, shouldn't that be something like <= .05f or something closer to zero?

Comment
Add comment · Show 8 · 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
avatar image Mmmpies · Mar 04, 2015 at 03:34 PM 0
Share

Print is a wrapper around Debug.Log in $$anonymous$$onoBehaviour, they should be ok using it as the script inherits from mono Although I use debug myself.

avatar image KnightRiderGuy · Mar 04, 2015 at 05:29 PM 0
Share

Thanks tigertrussell, yup, that was what I was doing wrong... I usually do use the Debug.Log but the guy on YouTube who had the tutorial was using the print, plus I tweaked the code to run the fill in reverse of what he had in his tutorial, but the last part of the script was confusing me. Now it works so I can make it do something once it gets to the end now.

On Another not I wonder if I can use what you have done here to also change the colour of the fill bar when it gets to a certain level and even add a voice clip or warning siren.? I think I have a pretty good idea of how to do that with the render.material stuff.

This is cool, thanks guys, this was a BIG help :)

avatar image KnightRiderGuy · Mar 04, 2015 at 05:51 PM 0
Share

Yup, As I suspected I can just add some If Statements and get the exact point of the bar I want to add in any sound or colour change... Cool :)

 ![void Update (){
         DeathTimerBar.fillAmount -= DecreaseAmount * Time.deltaTime;
         //Bar In Yellow Zone
         if (DeathTimerBar.fillAmount <= 0.56f) {
             Debug.Log ("You Are In The Yellow!");
 
         }
         //Bar In Red Zone
         if (DeathTimerBar.fillAmount <= 0.32f) {
             Debug.Log ("You Are In The Red!");
             
         }
         //Bar At End Now You Gonna Die $$anonymous$$utha Fuka
         if (DeathTimerBar.fillAmount <= .01f) {
             Debug.Log ("You All Out Of Air $$anonymous$$utha Fuka!");
             this.enabled = false;
         }
     }][1]


[1]: /storage/temp/41819-screen-shot-2015-03-04-at-115106-am.png

screen-shot-2015-03-04-at-115106-am.png (134.4 kB)
avatar image KnightRiderGuy · Mar 04, 2015 at 06:28 PM 0
Share

Ha ha... ok this was kinda bizarre but yet potentially useful for distorting sounds, $$anonymous$$ay be useful for later, I put a playOneShot audio clip in the If part of the code and when it hit the yellow zone it platy the audio clip backwards, sounded like the aliens were invading. Now what I want but I could find a use for that effect later on for sure ;)

avatar image tigertrussell · Mar 04, 2015 at 07:17 PM 0
Share

Lerping the pitch is also a good way to get a time-dilation effect on sound :) Glad I could help!

Show more comments

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity 5 - Time counter Up script (millisecond precision) UI 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How to animate RectTransform change in position 1 Answer

Options UI over all scenes 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