in Education by
I'm trying to implement a functionality that can determine which word in the text the user clicked on. To do this, I use the TextMeshProUGUI element and the following code: using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; public class ExtraWordsDefinition : MonoBehaviour { public TextMeshProUGUI text; public string LastClickedWord; void Start() { text = GetComponent(); } private void Update() { if (Input.GetMouseButtonDown(0)) { var wordIndex = TMP_TextUtilities.FindIntersectingWord(text, Input.mousePosition, null); if (wordIndex != -1) { LastClickedWord = text.textInfo.wordInfo[wordIndex].GetWord(); Debug.Log("Clicked on " + LastClickedWord); } } } }` This code works fine if the text in the element is static (i.e.the text that I specified in the component's settings in the Unity inspector) then the words I click on are displayed in the console. But, if I try to change the text of the component dynamically through the code, then the script stops detecting clicks on the text at all (the if condition does not work). Also, this way of changing text resets the text alignment settings. At first I made code where the text was changed by assigning a new string to the ".text" property, but I also tried changing the text through the SetText() method, but that didn't change anything. Unfortunately, searching the internet didn't help me find an answer either. Please help me figure out what is the reason. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
First, I would add logs to verify that the mouse Vector and the TextMesh Vector are compatible. If that is the case, I would add a print when the test is updated and when the mouse is pressed to verify that the mouse pressing happens after the text has been updated and that the positions are still correct. I would also print the index to see if the text is actually found at the given position or if there is another problem. Also, ensure that nothing has a higher layer order than the text mesh after you change the text.

Related questions

0 votes
    Question: how to get the limits of the camera when it is with the pixel perfect effect since having ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    I have a method that uses Gamespark Api to get leaderboard data. I want to return that data to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    Page has a table populated with user1's information. When node is clicked to select user2, table data is ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 19, 2022 in Education by JackTerrance
0 votes
    I have been trying to use the Rekognition API to detect text in an image. I have enabled full ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    How to detect text orientation in an image? It doen't matter if the orientation is upside down (180 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    Ok, I'm doing a bunch of RIA/AJAX stuff and need to create a "pretty", custom confirm box which ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 10, 2022 in Education by JackTerrance
0 votes
    Ok, I'm doing a bunch of RIA/AJAX stuff and need to create a "pretty", custom confirm box which ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 10, 2022 in Education by JackTerrance
0 votes
    Background: I have an old web CMS that stored content in XML files, one XML file per page. I am ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 10, 2022 in Education by JackTerrance
0 votes
    On device with compute capability...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    I want to combine two views in one dashboard in google analytics report. I want the tracked buttons up ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    I want to combine two views in one dashboard in google analytics report. I want the tracked buttons up ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 6, 2022 in Education by JackTerrance
0 votes
0 votes
    Difference between Clicks and Visits in Google Analytics?...
asked Oct 3, 2020 in Technology by JackTerrance
0 votes
    I have been developing a webpage which uses n number of dropdownlists which are binding dynamically inside a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
...