SHADE_Y3/Assets/Scripts/UI/SC_ScoreTextDigitPositionin...

43 lines
998 B
C#

using SHADE;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SHADE_Scripting.UI
{
public class ScoreTextDigitPositioning:Script
{
[NonSerialized]
Vector3 defaultPosition;
public float offsetPerDigit = 0.0f;
protected override void awake()
{
Transform trans = GetComponent<Transform>();
if(trans)
{
defaultPosition = trans.LocalPosition;
}
}
protected override void update()
{
TextRenderable text = GetComponent<TextRenderable>();
Transform trans = GetComponent<Transform>();
if (trans && text)
{
String str = text.Text;
Vector3 offset = new Vector3((str.Length - 1) * offsetPerDigit, 0.0f, 0.0f);
trans.LocalPosition = defaultPosition - offset;
}
}
}
}