K
K
Kara_St2021-10-02 19:34:48
Helpdesk
Kara_St, 2021-10-02 19:34:48

How to display a random phrase from a list (C# Unity)?

Let's say I have a list of phrases: "a", "b", "c" And I need to display one of them in
Textmesh Pro
another day)
How to do it?
I'm new to Unity, so sorry if I wrote something wrong

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MrAfitol, 2021-10-02
@Kara_St

private System.Random rnd = new System.Random();

    void Start()
    {
         List<string> ranS = new List<string>()
         {
             "a",
             "b",
             "c"
         };

         Debug.Log(ranS[rnd.Next(0, 3)]);
    }

But always in rnd.Next(0, 3) you need to put 1 more than there is, and we start not from 1 but from 0

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question