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 DayyanSisson · Aug 07, 2012 at 05:57 PM · materialresetfadesendmessage3d text

Fading 3D Text

I've written this script here to make 3D text display the amount of damage dealt, rise up, then fade out. Since I don't want to have to Instantiate this 3D text over and over again, I'm just trying to re-use the same ones. It works at first, and fades out. For some reason though, once the text is Reset, it no longer fades out. And it looks all weird and blocky when the game starts, and it creates an instance of the the material.

 public float fadeDelay = 1;
  public float fadeRate = 10;
  public float floatVelocity = 3;
 
  private Transform parentD;
 
  private float xVel;
  private float zVel;
 
  public bool fading = true;
  public Color newColor;
 
  private Transform display;
  private TextMesh tM;
 
  void Awake () {
 
  display = transform;
  newColor = display.renderer.material.color;
  parentD = display.parent;
  tM = display.GetComponent<TextMesh>();
  }
 
  void Update () {
  
  if(fading){
  Vector3 floatDir = new Vector3(xVel, floatVelocity, zVel);
  display.Translate(floatDir * Time.deltaTime);
  StartCoroutine(Fade());
  }
  }
 
  IEnumerator Fade () {
 
             yield return new WaitForSeconds(fadeDelay);
  newColor.a -= fadeRate * Time.deltaTime;
  display.renderer.material.color = newColor;
  if(display.renderer.material.color.a <= 0){
  display.renderer.enabled = false;
  fading = false;
  parentD.SendMessage("AddDisplay", display);
  }
  }
 
  void Reset () {
 
  if(fading) return;
 
  display.renderer.enabled = true;
  newColor.a = 100;
  if(Random.value > 0.5F){
  xVel = -floatVelocity;
  }else{
  xVel = floatVelocity;
  }
  if(Random.value > 0.5F){
  zVel = -floatVelocity;
  }else{
  zVel = floatVelocity;
  }
  fading = true;
  }

Not sure whats going wrong here. Reset() is called by the parent, which is what's re-using the 3D text. The overall effect is that when someone attacks someone else, and does damage, a red floating number emits from the other person displaying how much damage was dealt. I've got most of it, just not the resetting. How should I fix this?

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
1
Best Answer

Answer by Meltdown · Aug 07, 2012 at 06:03 PM

RGBA values in Unity are normalized. Setting newColor.a = 100; is an invalid value. It's range is only from 0 - 1.

So you may want to set it to 1 to make sure it shows correctly on reset.

Comment
Add comment · Show 2 · 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 DayyanSisson · Aug 07, 2012 at 06:09 PM 0
Share

Oh you're right! Yes, by setting to 100, it was fading out, but since it was at 100 it made no difference until a became less than 1... and it didn't even have that long to fade that much. Thanks!

avatar image IndieScapeGames · Aug 07, 2012 at 06:29 PM 0
Share

Nice answer.

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

9 People are following this question.

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

Related Questions

Material doesn't have property '_Color' 4 Answers

Fading multiple objects 0 Answers

Reset my (public)integers on GUI? 0 Answers

How to make 3D text fade with OnMouseEnter? 1 Answer

Gun Barrel To Get Hot - Change _Tint 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