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 /
avatar image
0
Question by daveinpublic · Oct 31, 2014 at 06:43 PM · guialpha4.6

Change new GUI over time - 4.6

Hi, I've been searching online, but can't find the right answers. I want text to pop up whenever I get a bonus, saying +5000 or +100... I'm also trying to make it shrink and fade out after a second. This is what I have so far:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class Script_CanvasScoreBonus : MonoBehaviour {
 
     Text textBonus;
     float textBonusAlpha;
     
     void Start () {
         textBonus = gameObject.GetComponent<Text>();
         textBonusAlpha = textBonus.color.a;
         textBonus.enabled = false;
     }
 
     public IEnumerator displayBonusEn (string displayText) {
         textBonus.enabled = true;
         textBonusAlpha = 1;
         textBonus.text = displayText;
         while (textBonusAlpha > 0) { textBonusAlpha -= .05f; 
         yield return null; }
         textBonus.enabled = false;
     }
 }

I have this script attached to a text object called 'Bonus Text':

alt text

This script is then called when a player gets a bonus - which passes in a string like "+5000". Everthing works - the "+5000" shows in my game at the right time, and it goes away after about a second - but it's not fading out, it just goes away. It's there when I need it, and completely gone in a second. I was initially doing -= Time.deltaTime * 2... Depending on what I put there - 2, 3, .5, it changes the length of time that the text stays up - if I put 2 than it lasts for a second, 3 lasts for a second and a half... I was initially not using a variable for 'textBonusAlpha' and just using textBonus.color.a instead, but I got this error: "Script_CanvasScoreBonus.cs(20,56): error CS1612: Cannot modify a value type return value of `UnityEngine.UI.Graphic.color'. Consider storing the value in a temporary variable" - Can't seem to figure this out!

Also - could someone please tell me how to access the font size in the code? I know alpha is xxx.color.a - I want to decrease the font size gradually, as well. Thank u in advance!

screen shot 2014-10-31 at 12.32.50 pm.png (11.7 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by drod7425 · Oct 31, 2014 at 06:57 PM

You can do this pretty easily in 4.6 with UI transitions. You do not need to do this through code. This video explains it very well:

http://unity3d.com/learn/tutorials/modules/beginner/ui/ui-transitions

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

Help with destroying guiRect? 0 Answers

Strange shader behaviour on UI component 0 Answers

v4.6 UI Element's Positioning Incorrect 1 Answer

Prefab as a Sprite 0 Answers

Change texture alpha value on runtime 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