Untitled
unknown
plain_text
5 months ago
756 B
1
Indexable
Never
public TMP_InputField inputField; public TMP_Text speedText; float startTime; int charactersTyped; void Start() { // Attach the OnValueChanged listener to the input field inputField.onValueChanged.AddListener(OnValueChanged); } void OnValueChanged(string text) { // Start measuring typing speed when the first character is entered if (charactersTyped == 0) { startTime = Time.time; InvokeRepeating("UpdateSpeed", 0f, 1f); // Update speed every second } charactersTyped = text.Length; } void UpdateSpeed() { float timeElapsed = Time.time - startTime; int cpm = Mathf.RoundToInt(charactersTyped / timeElapsed * 60f); speedText.text = "Typing Speed: " + cpm + " CPM"; }