I am trying to write text in Hebrew, But there is a problem. Unity allows me to write text in direction from Left to Right, But I can’t write from Right to Left. And I can’t to do something good with the code, Because I think It is impossible.
I’m talking about the Text Component which located in the Canvas game object (The new UI which released in Unity 4.6).
The bad news is that right-to-left languages are not currently supported by our text system. This is definitely something to want to support, however, and it is on our roadmap, but I can’t make any predictions or guarantees when it will be available.
Using @cjdev 's string reversing code, I have come up with this script. See if it can help you.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
using System.Linq;
using System.Collections.Generic;
public class flipfont : MonoBehaviour {
Text myText; //You can also make this public and attach your UI text here.
string individualLine = ""; //Control individual line in the multi-line text component.
int numberOfAlphabetsInSingleLine = 20;
string sampleString = "I am trying to write text in Hebrew," +
"But there is a problem. Unity allows me to write text in direction from Left to Right, " +
"But I can't write from Right to Left. And I can't to do something good with the code, " +
"Because I think It is impossible.";
void Awake(){
myText = GetComponent<Text>();
}
void Start(){
List<string> listofWords = sampleString.Split(' ').ToList(); //Extract words from the sentence
foreach(string s in listofWords){
if(individualLine.Length >= numberOfAlphabetsInSingleLine){
myText.text +=Reverse(individualLine)+"
"; //Add a new line feed at the end, since we cannot accomodate more characters here.
individualLine = “”; //Reset this string for new line.
}
I have made an asset that inherits from InputField and allows for RTL editing.
I’m still fleshing out the editing and integrations, but the core functionality is there (and does the job)