Game Dev Journey Day 3

Chris Didier
2 min readMar 23, 2021

Today I jumped into day 3 of working with the C# survival guide and today was a little bit of optimization. If it can help improve efficiency it is always something to look into and learn about.

Having lots of if statements is not very efficient so it is better to have a switch statement in place if you are having to use multiple if else statements to complete a task.

Useable but inefficient

Yes, this will still get the job done, but it is more efficient to use a switch like this.

Switch case more efficient same results

Next I converted more if statements into switch statements. In the video below the scores were originally being found by being in an in if ladder, but it was more efficient to use a switch statement in this case.

Next was changing the color of the cube based upon the material color selected within the switch statement. This was done by going into cube, finding the mesh renderer, and changing the material color. With each color assigned to a button you could change the color based upon what button you had selected.

Color changing cube

Finally, I created a weapon selection system using switch statements. Based upon the input the player enters, they will be able to select whether a gun, knife, or machine gun is their selected item at the time.

--

--