Search Unity

Question Cannot implicitly convert type 'string' to 'TMPro.TextMeshProUGUI'

Discussion in 'UGUI & TextMesh Pro' started by aiyan21, Mar 13, 2023.

  1. aiyan21

    aiyan21

    Joined:
    Mar 1, 2023
    Posts:
    21
    Hello im trying to put a string to a textmeshpro text but this error keeps showing up.
    upload_2023-3-13_19-43-50.png
    here's my codes:
    Code (CSharp):
    1.  
    2.     [SerializeField]
    3.     public TextMeshProUGUI resulttxt;
    4.     [SerializeField]
    5.     public TextMeshProUGUI explanationtxt;
    6.     private string infp;
    7.  
    8.  
    9.     void Start()
    10.     {
    11.         resulttxt.text = PlayerPrefs.GetString("typeA") + PlayerPrefs.GetString("typeB") + PlayerPrefs.GetString("typeC") + PlayerPrefs.GetString("typeD");
    12.         ExplainType();
    13.     }
    14.  
    15.     void ExplainType()
    16.     {
    17.         if (resulttxt = "INFP")
    18.         {
    19.             infp = "ate angel ganda";
    20.             explanationtxt.text = infp;
    21.  
    22.         }
    23.     }
    UI view:
    upload_2023-3-13_19-42-32.png
     
  2. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    660
    if (resulttxt = "INFP")

    should be

    if (resulttxt.text == "INFP")
     
    Last edited: Mar 13, 2023