I downloaded a font for Hindi Language (k010.ttf).
I have a menu for the game. In that I have a button (Language Change). On click of that button the fonts of language should change from English to Hindi.
I wrote this script:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class LangChng : MonoBehaviour {
//public Font myNewFont;
public GameObject go1;
public GameObject go1b1;
public GameObject go1b2;
public GameObject go1b3;
public GameObject go1b4;
public GameObject go1b5;
public GameObject go2;
public GameObject go2b1;
public GameObject go2b2;
public GameObject go2b3;
public GameObject go2b4;
public GameObject go3;
public GameObject go3b1;
public GameObject go3b2;
public GameObject go3b3;
public GameObject go3b4;
public GameObject go3b5;
public GameObject go3b6;
public GameObject go3b7;
public GameObject go4;
public GameObject go4b1;
public GameObject go5b1;
public GameObject go5b2;
public GameObject go5b3;
//public Button but;
// Use this for initialization
public void onClick ()
{
go1.SetActive (true);
//go1.SetActive (true);
go1b1.GetComponentInChildren<Text>().text = "Vs CPU...";
go1b2.GetComponentInChildren<Text>().text = "Vs Player...";
go1b3.GetComponentInChildren<Text>().text = "High Score...";
go1b4.GetComponentInChildren<Text>().text = "Options...";
go1b5.GetComponentInChildren<Text>().text = "Exit...";
//go1.SetActive(false);
go1.SetActive(false);
go2.SetActive (true);
//go1.SetActive (true);
go2b1.GetComponentInChildren<Text>().text = "Back...";
go2b2.GetComponentInChildren<Text>().text = "Slow...";
go2b3.GetComponentInChildren<Text>().text = "Rock...";
go2b4.GetComponentInChildren<Text>().text = "Pop...";
//go1.SetActive(false);
go2.SetActive(false);
go3.SetActive (true);
//go1.SetActive (true);
go3b1.GetComponentInChildren<Text>().text = "Help...";
go3b2.GetComponentInChildren<Text>().text = "Credits...";
go3b3.GetComponentInChildren<Text>().text = "About...";
go3b4.GetComponentInChildren<Text>().text = "Sound...";
go3b5.GetComponentInChildren<Text>().text = "Music...";
go3b6.GetComponentInChildren<Text>().text = "Language...";
go3b7.GetComponentInChildren<Text>().text = "Back...";
//go1.SetActive(false);
go3.SetActive(false);
go4.SetActive (true);
//go1.SetActive (true);
go4b1.GetComponentInChildren<Text>().text = "Back...";
//go1.SetActive(false);
go4.SetActive(false);
go5b1.GetComponentInChildren<Text>().text = "English...";
go5b2.GetComponentInChildren<Text>().font = Resources.GetBuiltinResource(typeof(Font), "k010.ttf") as Font;
//go5b2.GetComponent<Text>().font = Resources.GetBuiltinResource<Font>("k010.ttf");
//go5b2.GetComponent<Text>().font = myNewFont;
go5b2.GetComponentInChildren<Text>().text = "asd";
go5b3.GetComponentInChildren<Text>().text = "Back...";
}
}
I downloaded the font file and put it in the Assets folder. However the code is not running and giving the error:
Failed to find k010.ttf
UnityEngine.Resources:GetBuiltinResource(Type, String)
LangChng:onClick() (at Assets/Scripts/LangChng.cs:83)
UnityEngine.EventSystems.EventSystem:Update()
The resource k010.ttf could not be loaded from the resource file!
UnityEngine.Resources:GetBuiltinResource(Type, String)
LangChng:onClick() (at Assets/Scripts/LangChng.cs:83)
UnityEngine.EventSystems.EventSystem:Update()