Tutorial: Hello World - CodingDino/Dino-Unity-Toolkit GitHub Wiki

Welcome to the Dino Toolkit! This tutorial is a "Hello World", a programming tradition when using a new tool or language. In this tutorial, you will learn to use an Activator to trigger an Action, which is the basis for how everything in the Dino Toolkit works. The Activator will be a key press, and the Action will be to print the words "Hello World" to the developer console.

Before you start, make sure you have downloaded and imported your toolkit. You can use the How To Install Tutorial to do this.

The GameObject

Our Actions and Activators in the Dino Toolkit are components. Components control data and logic in the game. All components must be attached to GameObjects, the basic building block of a Unity game.

To start off our tutorial, we need a GameObject to attach our Activator and Action to. Add an empty GameObject to your scene by going to the GameObject menu and selecting "Create Empty". Right-click you new GameObjet in the hierarchy and select Rename, and call your GameObject "Hello World Printer".

Empty GameObject

Note: Your GameObject won't look like anything in your scene or game views - that's because it doesn't have a Renderer Component. For this tutorial, we don't need it to be visible, so we won't be adding one.

The Action

Everything in the Dino Toolkit can be thought of as Activators and Actions. The Action is the thing we want to happen - the Activator is the condition triggering that Action. In our case, the Action is printing "Hello World" to the console. To do this, we need a ConsoleAction component.

Select your "Hello World Printer" GameObject and look at the inspector panel. Click the "Add Component" button and type in "ConsoleAction", then click it to add the component. Your new ConsoleAction component doesn't have any fields - it's nice and simple!

ConsoleAction component

The Activator

In the Dino Toolkit, Actions can't just happen by themselves - they must be triggered by an Activator. In our case, we want to print out the words "Hello World" when we press a button, so we need an InputButtonActivator to trigger our ConsoleAction.

Add a new component to your "Hello World Printer" GameObject by selecting it and clicking "Add Component" in the inspector panel. This time, search for "InputButtonActivator" and select it.

InputButtonActivator

There's a lot more information on this Component than on the last one! That's because we need to give this component some settings. First of all, we need to tell it what button we care about. For now, let's use the "Jump" button. By default in Unity this is set up to be the space bar.

To set up the button, simply type "Jump" in the "Button" field for our InputButtonActivator component.

Button Name

Next, we need to tell the Activator what Action it should trigger. This Activator has several action lists, which get triggered depending on if the button was just pressed down, just released, or being held down. In our case we'll keep it simple - we'll use the first action list, On Button Pressed (), which happens when the button is first pressed down. We need to add a new Action to this list, so click the + button on the list's field.

Add to list

A new entry in the list will be created. Each entry in the Action list has several fields. The first one we care about is the GameObject field. This tells the Activator what GameObject has the Action it should trigger. In this case, it's the same GameObject that our Activator is on, but our Activator can't know that on its own. We need to drag the GameObject in to the slot on the action list entry to link them up.

Drag Here

Now the Activator knows what GameObject to use, but not what specific Action to trigger. Use the drop down menu to select our ConsoleAction. In the sub-menu, choose ActionPrintLog. You'll see many other options - most of these are built in Unity functions. There are two other Actions available in the list - ActionPrintError and ActionPrintWarning. You can try those out later.

Select Action

When you have selected ActionPrintWarning as the Action our Activator should take, you will see a new field appear. This is the text that will be printed when the Activator is triggered. Activators can sometimes pass along extra information like this to the Action - it just depends on what the Action is. In this case, let's type "Hello World" into the box so that "Hello World" is printed to the console when the button is pressed.

Printed Text

Testing

That's everything set up - now to see if it works! First, we need to actually have our console panel out so we can see if anything gets printed to it. Make sure it is open by selecting Window > General > Console.

To test our game, we need to press Play at the top of the Unity window. The game is now running, but nothing will happen - that's because we haven't told anything to happen until we press the "Jump" (space) key! Press the space key while the game panel has focus. You should see a new line appear in your console, saying "Hello World". Success!

Testing

If the message did not appear, or you get error messages, make sure you have typed "Jump" correctly in your button name field on the InputButtonActivator - remember that in game development, spelling and capitalisation usually has to match exactly for things to work! If it's still not working, go over the previous steps carefully to determine where things went wrong.

Challenge

You got the basics working - great job! Now to try some new things to test and build on your understanding so far. Try the following challenges on your own:

  • Make it print a different message, such as "Howdy partner!" or anything you like.
  • Change the print action - try the Warning and Error versions, and see the difference. These use Unity's built in logging functionality, so you can sort and filter them based on the log type. Useful!
  • Make it print something different when the button is released. You can even try printing while the button is held down - use the Cooldown field to make this less spammy.
  • Change the button that must be pressed to print out the message. You can see what buttons Unity has built in by going to Edit > Project Settings > Input. You can even customise and change these - just remember, spelling and capitalisation matters! You might want to look at Unity's key input informationfor details on how to map to different keys.
  • Change the Action that is carried out. You can try some of the other Action scripts instead of just printing to the console. Maybe you want to play a sound, spawn a block, move into the air - there are many Actions available!
  • Change the Activator that triggers the action. You can have the action triggered every frame, when the game starts, when two objects bump into eachother, when a timer runs down - there are lots of Activators available!

Once you are done experimenting, why not try out making a player move around and jump using the Platform Movement Tutorial? Good luck and have fun!