Using an integer data type to control functions in Unity

Zac Bogner
2 min readJan 4, 2024

--

Recently, while working on projects I’ve been wondering why my methods or functions wouldn’t execute code correctly, even though it seems correct. However, I discovered a solution that’s modular and error free for my use cases using integers to pass in data.

Below is the output when the E button is pressed twice. We notice that the second E method does not call in the code block made.

To solve it, we can create a data type integer i to store and pass in our data.

First, we need to increment i from 0 and check if i <or equal to 0.

Once we check for i, we assign i to equal 1.

Next we do the inverse operation of i, checking if i >or equal to 1. Then decrement 1 from i.

Now, when we set it again to 0, from 1. We can loop back into our first input action called, the first E.

With this script, we can use it’s base class information to modularize our code in future projects.

--

--

Zac Bogner
Zac Bogner

Written by Zac Bogner

Game Designer and Level Designer, formerly with Rainbow Studios. Focused in Unreal Engine with experience in Unity. Former Race Car Driver.

No responses yet