Search Unity

Text prefab

Discussion in 'Prefabs' started by kqmdjc8, Mar 28, 2019.

  1. kqmdjc8

    kqmdjc8

    Joined:
    Jan 3, 2019
    Posts:
    102
    Hello guys. I've made simple combo system but I'm getting strange error.

    Code (CSharp):
    1. if (other.gameObject.tag == "Player") //if hit confirm box collided with player
    2.         {
    3.             comboTextTemp = Instantiate(comboText, other.transform.position, Quaternion.identity);
    4.             comboTextTemp.GetComponent<TextMeshProUGUI>().text = player.combo.ToString();
    5.         }
    It says that comboTextTemp is never assigned and I cant use it. For me everything seems fine

    What may be a solution?
     
  2. kqmdjc8

    kqmdjc8

    Joined:
    Jan 3, 2019
    Posts:
    102
    It's strange, because IT IS assigned because I can controll it's position. This works fine:
    Code (CSharp):
    1. if (other.gameObject.tag == "Player") //if hit confirm box collided with player
    2.         {
    3.             comboTextTemp = Instantiate(comboText, other.transform.position, Quaternion.identity);
    4.             //comboTextTemp.GetComponent<TextMeshProUGUI>().text = player.combo.ToString();
    5.             comboTextTemp.transform.position += new Vector3(2, 0, 0);
    6. }
     
  3. kqmdjc8

    kqmdjc8

    Joined:
    Jan 3, 2019
    Posts:
    102
    Well. Ok. Sometimes you need to describe problem to solve it yourself. In GetComponent use TextMeshPro instead of TextMeshProUGUI