Random state

I am trying to make Random state select in the array after I click on the mouse button

We can’t see enough of the code and you are referencing variables that we can’t see.

You could do it by having a list of all the text states, and then picking one from there

[SerializeField] TextState[] allTextStates;
public TextState GetRandomTextState()
{
    return allTextStates[Random.Range(0, allTextStates.Length)];
}

then call it from the Clickonme method

public void Clickonme()
{
    if (Input.GetMouseButtonDown(0))
    {
        textState = GetRandomTextState();
        textComponent.text = textState.GetChrismasText();
    }
}

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms