H
H
HapBox2018-12-12 22:41:03
C++ / C#
HapBox, 2018-12-12 22:41:03

How can I make random numbers through a sprite?

5c11642f3de5d480349710.png

public TextMesh tm;
    Rigidbody2D rb;
  void Start ()
    {
        rb = GetComponent<Rigidbody2D>();
        tm = GameObject.Find("numBug").GetComponent<TextMesh>();
        tm.text = Random.Range(1, 255);
    }

tried that, but it doesn't work. What to do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Almost, 2018-12-13
@HapBox

If I understand correctly, then tm.text is of type string, and Random.Range(1,255) is of type int, and you are assigning int to string. Try this:
tm.text = Random.Range(1, 255).ToString();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question