Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Can't Convert integer List to Text List (Please Help!)

Discussion in 'Scripting' started by gsammbunny, Sep 13, 2018.

  1. gsammbunny

    gsammbunny

    Joined:
    Mar 7, 2016
    Posts:
    66
    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEngine;
    3. using UnityEngine.UI;
    4.  
    5. public class TextManager : MonoBehaviour
    6. {
    7. public List<Text> TextList;
    8.  
    9. private void Start()
    10.     {
    11.         TextList = new List<Text>();
    12.  
    13.         TextList [0] = CoreLogic.instance.BaseList[0].ToString();
    14.     }
    15. }
    Note: I'm getting the reference of an int Type BaseList containing some values from an instance of another class "CoreLogic.cs"
     
  2. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    The type UnityEngine.UI.Text has a Text property of type string, so you're most-likely looking for

    Code (csharp):
    1. textInstance.Text = yourString;
    In your particular case, you want something like

    Code (csharp):
    1. TextList[0].Text = CoreLogic.instance.BaseList[0].ToString();
    However, if that's all the code you got, you will need to remove the first line in your start function, otherwise the next error you'll run into will be a NullReferenceException.
     
    dato818 likes this.
  3. gsammbunny

    gsammbunny

    Joined:
    Mar 7, 2016
    Posts:
    66
    Thank you very much works perfectly.