Below is a tutorial detailing how to move something to a desired location when you press a button. It will go over how to use the "InputGetKey" script, the "SingleMove" script, and how to use them together to produce the desired behavior.
This section will show a simple implementation of the "InputGetKey" script. You can apply the method in this section to trigger any Endless Event on any button down you want. If you do not have a project you are currently working in, open up "Barebones Game" in the Editor.
- Start by Right-Clicking on "Gameplay" in the project hierarchy, and select "Create Empty". Rename this empty entity "Button Press Entity". This will be Entity that you attach the script to. In order for you to have a script do something in your project, you always will need an Entity to attach it to.
- Search for "InputGetKey" in the Library with the "Endless" tab selected. Drag the script "InputGetKey" from the Library onto "Button Press Entity".
- For this example, we are just going to make you win the game if you press "p".
- Press the "+" button beneath "On Button Down ()" Endless Event on the "InputGetKey" script you just added.
- Drag "GameplayLogic" from your Project Hierarchy onto where it says "No Target" beneath "On Button Down ()". Choose "PlayerWon()" from the dropdown that says "No Function"
- Finally change the "Key Name" variable on "InputGetKey" to "p" (without the quotes). You can put any key here really.4
- Play the scene, and press "p". You will see that you will win the game by pressing whatever key you put in the "Key Name" field.
This section of the Wiki will detail how to move an object from point A to point B using the "SingleMove" script. If you have completed "The InputGetKey Script," you can do this all in the same scene. You may also start from scratch by opening "Barebones Game" in the editor.
- Right-Click on "Gameplay" in your Project Hierarchy and select "Create Empty" from the dropdown that appears. Rename this entity to "Moving Object".
- Drag an object you want to move automatically onto "Moving Object" from the Library. For this tutorial, we will be moving "Racer Light Visuals"
Combining InputGetKey and Single Move To Move An Object on a Button Press[edit | edit source]