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.
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*.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*;_
_ uiVertex.color = Color32.Lerp(bottomColor, topColor, (uiVertex.position.y - bottomY) / uiElementHeight);_ _ vertexList = uiVertex; } } }* If you want to combine this with UI/Outline or Shadow make sure this script is sitting above them in the inspector._