Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine.UI;
- using UnityEngine;
- public class AdaptiveFont : MonoBehaviour
- {
- Text txt;
- public bool continualUpdate = true;
- public int fontSizeAtDefaultResolution = 24;
- public static float defaultResolution = 2229f;
- // Use this for initialization
- void Start ()
- {
- //print(Screen.height + Screen.width);
- txt = GetComponent<Text>();
- if(continualUpdate)
- {
- InvokeRepeating("Adjust", 0f, Random.Range(0.5f, 2f));
- }
- else
- {
- Adjust();
- enabled = false;
- }
- }
- void Adjust()
- {
- if (!enabled || !gameObject.activeInHierarchy)
- {
- return;
- }
- float totalCurrentRes = Screen.height + Screen.width;
- float perc = totalCurrentRes / defaultResolution;
- int fontsize = Mathf.RoundToInt((float)fontSizeAtDefaultResolution * perc);
- txt.fontSize = fontsize;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement