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 Anni2D · Jul 25, 2014 at 09:43 AM · fontgradientbitmap

How to create gradient text

I want to use gradient font in my game for displaying score on top of screen, but without NGUI and 2DToolkit. By searching, I came up with Bitmap Font File. I have used Littera in order to create font files. It generates a .fnt file along with a png file.

I have found this link, telling you how to import these files in unity. But how can I use them? Or Is there any other better method of achieving my goal? Thanks.

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 Pendrokar · Jul 25, 2014 at 10:19 AM 0
Share

Would this gradient effect also be on a single letter? Or is having each letter a different color enough?

2 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by Noxury · May 20, 2017 at 07:07 PM

Attach this script to a text gameobject:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine.UI;

 [AddComponentMenu("UI/Effects/Gradient")]
 public class Gradient : BaseMeshEffect {
     [SerializeField]
     private Color32 topColor = Color.white;
     [SerializeField]
     private Color32 bottomColor = Color.black;

     public override void ModifyMesh(VertexHelper vh){
         if (!this.IsActive())
             return;

         List<UIVertex> vertexList = new List<UIVertex>();
         vh.GetUIVertexStream(vertexList);

         ModifyVertices(vertexList);

         vh.Clear();
         vh.AddUIVertexTriangleStream(vertexList);
     }

     public void ModifyVertices(List<UIVertex> vertexList) {
         int count = vertexList.Count;
         float bottomY = vertexList[0].position.y;
         float topY = vertexList[0].position.y;

         for (int i = 1; i < count; i++) {
             float y = vertexList[i].position.y;
             if (y > topY) {
                 topY = y;
             } else if (y < bottomY) {
             bottomY = y;
             }
         }

         float uiElementHeight = topY - bottomY;

         for (int i = 0; i < count; i++) {
             UIVertex uiVertex = vertexList[i];
             uiVertex.color = Color32.Lerp(bottomColor, topColor, (uiVertex.position.y - bottomY) / uiElementHeight);
             vertexList[i] = uiVertex;
         }
     }
 }

If you want to combine this with UI/Outline or Shadow make sure this script is sitting above them in the inspector.

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 Jamy4000 · Aug 01, 2017 at 12:49 PM 0
Share

Thank you really much for your code, it work perfectly ! Could you just tell me how to make this gradient horizontal and not vertical please ? :)

avatar image Jamy4000 Jamy4000 · Aug 01, 2017 at 01:55 PM 0
Share

Never$$anonymous$$d, found it myself, thank you again for your code ! If someone end up here by any chance, you just have to change the position.y by position.x, and if you want something clean, modify all variables names that contain y (topY, bottomY, ...)

avatar image
0

Answer by Pendrokar · Jul 25, 2014 at 10:22 AM

It generates a .fnt file along with a png file.

How can I use these or convert them to use in Unity?

You need to convert them to either ".ttf", ".dfont" or .otf format.

Supported Font formats are TrueType Fonts (.ttf or .dfont files) and OpenType Fonts (.otf files). http://docs.unity3d.com/Manual/class-Font.html

Comment
Add comment · Show 1 · 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 Anni2D · Jul 25, 2014 at 11:25 AM 0
Share

Thanks for reply @Pendrokar. As I mentioned a link, it tells you to convert .fnt file to .txt. and assign it to a material. What can i do next?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity custom font shader 0 Answers

How to find a font via script? 2 Answers

Is there a way to measure the pixel with/height of a string with a given font? 2 Answers

Preferred Vertical Size not Working with Custom Bitmap Font 0 Answers

Unity3D - How To Use BitMap Font 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