Help - Value Chat Commands

Does anyone have any idea how to make chat commands with values?

For example: /spawn box 5 – to spawns 5 boxes

All posts and videos i have seen have only /spawn box - or just /spawn, which is sadly not what i require :confused:

Split the string by space into an array and treat each element as an argument.

String[] command = chatText.split(' ');

// [0] = /spawn, [1] = box, [2] = 5
if(command[0] == "/spawn")
{
    if(command.Length == 3)
    {
        if(command[1] == "box")
        {
            int boxCount = 1;
            int.TryParse(command[2], out boxCount);

            spawnBox(boxCount);
        }
    }
    else if(command.Length == 2)
    {
        if(command[1] == "box")
             spawnBox(1); // spawn 1 box as default if you don't specify a number
    }
    else
    {
        Debug.Log("Invalid arguments");
    }
}
1 Like

Thanks, ill try it out now!