Hello devs Good Evening/Morning.
I want to change a color of an individual alphabet of UI Text from scrip using tags of rich color, following is the snippet code I’m trying to get it done with ` void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag == “Player”)
{
// Destroy(col.gameObject);
char cubealphabet=gameObject.GetComponent().alphabet.text[0];
Debug.Log(cubealphabet);
string currentword = GameObject.Find(“GameController”).GetComponent().currentword;
//Debug.Log(“current word from destroyer”+GameObject.Find(“GameController”).GetComponent().currentword);
if (GameObject.Find(“GameController”).GetComponent().wordbank.checkalphabet(currentword, cubealphabet) == true)
{
Debug.Log(“accurate alphabet”);
GameObject.Find(“GameController”).GetComponent().highlightalphabet(cubealphabet);
}
else
{
Debug.Log("Incorrect alphabet");
}
Destroy(gameObject);
}
}
`the variable cubealphabet just takes a single letter from the gameobject it is on,and it is sent to highlightalphabet function to change its color, following is the snippet code of highlighalphabet function
public void highlightalphabet(char colalpha)
{
int alphabetindex = wordfield.text.IndexOf(colalpha);
Debug.Log("Alphabet index is " + alphabetindex);
if (alphabetindex == -1)
return;
char coloredalpha=wordfield.text[alphabetindex];
//wordfield.text = "";
for (int i = 0; i <= wordfield.text.Length - 1; i++)
{
//wordfield.text +=currentword*;*
if(i==alphabetindex)
wordfield.text+= “<color=#FF0000>” + coloredalpha + “”;
}
}
the problem here is , I can’t seem to access an individual character in text with it’s respective index
like this
wordfield.text*=“”+coloredalpha+“”;*
the error i face here is “can not implicitly convert type string to char”
pardon if the question isn’t elaborated enough, but the bottom line is, I can’t apply richtext properties to an individual alphabets of UI.text.