Building an enterprise app — Generating a case number.

Esteban Ibarra
2 min readOct 3, 2021

--

To fill up our panels with info, today we’re given a challenge to generate a case number between 1 and 999 and assign it to the current case ID.

I did things a bit differently from the course as I wanted the client panel to hold the function of creating the generated number.

The random number creation was easy enough. I created a function called GenerateCase() in the ClientInfoPanel class that had this code:

But wait, wasn’t the number between 1 and 999 you may ask…Yes it was! I placed 1000 because Unity does things differently for ints in the random number generator and goes up to 1 less the latter number. If we were using floats, then I would stick with 999f, as it would go to the limit. Ints for some reason you need to subtract 1. Just one of those Unity things, I guess.

I also defined the function as int instead of void because I would be returning info in the form of an int number, and right after the random number generation, I do return the caseID back to whatever called the function.

Now let’s go into the UIManager:

I created holders for the ClientInfo panel and UIBorder Panels, so they’ll be immediately activated when the Create Case button is pushed:

the next line is the old activeCase = new Case(); which creates a new empty case for us to populate.

Right after that, I create a new variable called clientPanel of type ClientInfoPanel to keep things readable later, and I put the ClientInfoPanel component into it.

Next, I call the GenerateCase from that same clientPanel and then assign it to a variable called case ID which I then assign to the activeCase, but converted to a string.

Running the app now creates a new case number, places it into the active case and displays it on the client app!

--

--

Esteban Ibarra
Esteban Ibarra

Written by Esteban Ibarra

cartoonist, game artist, and wanabe gamedev.

No responses yet