Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Assets\Script\NilaiAkhir.cs(33,17): error CS0029: Cannot implicitly convert type 'UnityEngine.UI.Tex

Discussion in 'Scripting' started by aldi_aprilianto23, Jun 27, 2021.

  1. aldi_aprilianto23

    aldi_aprilianto23

    Joined:
    Jun 27, 2021
    Posts:
    2
    Assets\Script\NilaiAkhir.cs(33,17): error CS0029: Cannot implicitly convert type 'UnityEngine.UI.Text' to 'int'

    how to fix it ? anyone can help me?
     
  2. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,646
    aldi_aprilianto23 likes this.
  3. aldi_aprilianto23

    aldi_aprilianto23

    Joined:
    Jun 27, 2021
    Posts:
    2
  4. MaskedMouse

    MaskedMouse

    Joined:
    Jul 8, 2014
    Posts:
    1,091
    An implicit conversion of a UI.Text to int suggests that you're trying to convert a Text component to an integer rather than the actual string value of the Text component.

    You need to access the actual string from the component using the
    .text
    property.
    https://docs.unity3d.com/Packages/c...yEngine.UI.Text.html#UnityEngine_UI_Text_text

    Code (CSharp):
    1. int integerValue = int.Parse(textComponent.text);
    Code (CSharp):
    1. if(int.TryParse(textComponent.text, out int integerValue))
    2. {
    3.  
    4. }