Unity’s New Input System: Rapid Prototyping

Hello all!

Today, I will be going over using the new input system to rapid prototype any idea!

When I press space, start the charge bar

Setting up the Scene

  1. Create an UI image.
  2. Set its Pivot.x to 0. This will allow the image to grow out of its side.
  3. Set its position to wherever you need it.

Creating your C# Script

There is a way to use the new input system close to the old way. We used to use Input.GetKeyDown(Keycode.Space), but now we can use Keyboard.current.spacekey.isPressed. They both mean the same!

For that to work though, you need to add the UnityEngine.InputSystem; namespace.

You will also need to add the UI namespace to grab the RectTransform component from the UI image above.

Grab the reference to the RectTransform in the UI Image and make a float variable to hold the bar’s scale.

I set its local x scale to equal the _barScale variable. So, when I press the space key, the scale changes by 175 units per second. But when I let go, I lose 200 units per second.

I also set the bounds of the bar from 1–825 so it doesn’t fly off the screen.

This means we can just make a new project, slap a script on an object, and get your idea out there just as fast as before!

Next up, I will upgrade a script using the old input system to the new one!

See you then!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Marcus Cohee

Marcus Cohee

20 Followers

I am starting Unity and learning the ropes as I go! Let’s take this journey together!