Setting Up Buttons WITHOUT CODE in Unity

Rachel Stadler
4 min readMay 12, 2021

--

Want to make games? Scared of code? Don’t worry! You can get started in the Unity Game Engine without learning a programming language. Plus, knowing how the Unity Editor works will give you a great head start if you decide to learn C Sharp later. Making a game without code is a wonderful first step into game design!

This tutorial uses Unity 2020.2.1f1, and will assume you know the very basics of navigating the Unity Editor. If you don’t know what the hierarchy is, or how to add assets to your project, check out the Unity Manual’s interface section, or find a good basic tutorial to get you up to speed.

In this tutorial, we’ll set up the canvas, the UI layer that makes buttons in Unity work. Then I’ll show you how to set up the buttons themselves.

Setting Up the Canvas

First, you’ll need to set up the canvas. This is the layer that UI elements live on, so let’s make sure it’s set up properly. You can technically skip this step, but your buttons won’t be exactly where you want them when you play the program, so it’s best to set it up correctly in the first place.

Add a button to the scene, and Unity will automatically add a canvas.

Click the canvas, and find in the inspector the component called ‘Canvas’. Set the ‘Render Mode’ to ‘Screen Space- Camera’.

Now you need to tell the canvas which camera to pay attention to, even if there’s only one to choose from. (Computers are kind of dumb like that.)

Either drag the camera from your hierarchy into the box labeled ‘Render Camera’, or click on the little dot shown in the picture, and select Main Camera from the menu that appears.

If you are choosing from the menu and you don’t see what you’re looking for, make sure you’re on the tab called ‘Scene’ and not ‘Assets’.

And that’s it! You have successfully set up the canvas. You only need to do this once, at the beginning of the scene. If you start a new scene or project, you’ll need to set up the canvas again, but for now you’re good to go! Now you can add as many buttons as you like to the scene.

Setting Up Buttons

Now for the good stuff: making your buttons do things!

To give a button a job, click on it, then scroll down in the inspector until you see a window that says ‘on click’, and click the plus sign.

You’ll need to put an object in the box labeled ‘none’ for the button to boss around. You can put in an animation, a sound, a picture, or even the button itself! Like when we selected the main camera for the canvas, you can either drag objects in from your hierarchy, or you can click the little dot next to the box to see what’s available.

If you‘ve opened the menu and you can’t find what you’re looking for, make sure you’re in the right tab. ‘Assets’ contains all the things in your project dock(art, scripts, animators and animations, etc.), while ‘Scene’ has the objects in your hierarchy(cameras, buttons, canvas, etc.).

Once you’ve assigned an object to act on, you can choose something for the button to do with that object. Click the box currently labeled ‘No Function’ to see what’s available for the object you’ve assigned.

There are a ton of options here, but most of them are designed to work with code, so you can ignore them for now.

There are three main things you can tell a button to do without ever writing a line of code. Choose your own adventure: which functionality interests you most?

1) Make an object appear or disappear

2) Change what an object looks like

3) Make a sound play

You, yes, you, can make a game in Unity. It doesn’t have to be ground breaking. Either way, it will be a learning experience. The important thing is that you get out there and make something!

--

--

Rachel Stadler
Rachel Stadler

Written by Rachel Stadler

0 Followers

Likes reading, writing, programming and learning new things.

No responses yet