Here is the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using System.Text.RegularExpressions;
public class syntaxHighlter : MonoBehaviour
{
[SerializeField] private TMP_InputField inputField;
[SerializeField] private TextMeshProUGUI outputField;
string highlightedText;
private void Start()
{
inputField.onValueChanged.AddListener(OnInputValueChanged);
}
private IEnumerator UpdateOutputField(string text)
{
yield return new WaitForSeconds(0.1f); // delay for 0.1 seconds
outputField.text = text;
}
private void OnInputValueChanged(string text)
{
highlightedText = text.Replace("for", "<color=blue>for</color>")
.Replace("int", "<color=green>int</color>")
.Replace("float", "<color=green>float</color>")
.Replace("bool", "<color=green>bool</color>")
.Replace("void", "<color=green>void</color>");
Debug.Log(highlightedText);
StartCoroutine(UpdateOutputField(highlightedText));
}
}
I'm trying to make syntaxHighliter in TMP input field, I want for example if I type the word "mov" it immediatly changes color to blue, but here apparently the outputfield.text is not changing when I modify it here. I tried changing directly inputfield but that created an infinite loop, tried modifying input field resulted in an infinite loop