Estimated time to completion: 15 minutes
(excluding waiting times for downloads and installs)
- This introduction to Unity covers what's absolutely necessary to get you up and running
- You are here because you want to turn your dreams into reality by developing games or productivity apps
- We will be using Unity to make a simple Android application; advanced material is not covered here
- 0. Requirements
- 1. Installation
- 2. New Unity Project
- 3. Simple Application
- 4. Playmode Test
- 5. Building for Android
- 6. Android Mobile Phone Installation
- 7. Playing Your First Android Application
- 8. Experiment
- 9. Epilogue
You do NOT need to know how to program to complete this tutorial
- An Android mobile phone is required to test your application
- This tutorial was developed on Microsoft Windows 10 and Unity 2019
- Different versions of Unity may have slightly different menu placement, menu names, etc.
- Both Unity and Visual Studio Code are also available on Mac OS X and Linux
Two separate programs must be installed: VSCode and Unity
- Visual Studio Code (a.k.a. VSCode)
- Download and install Microsoft Visual Studio Code: https://code.visualstudio.com/
- Write down where you installed VSCode for a later step
-
Unity
- Depending on your internet and computer speeds, downloading and installing Unity will take a while (20+ minutes)
- You must sign up for a free account with Unity (https://id.unity.com)
- Download and install Unity Hub from: https://store.unity.com/download-nuo
- Open Unity Hub and sign into you Unity account
- On the left-hand menu, select
Installs
then click on the blueADD
button on the right, choose the latest version and click onNEXT
- You must select
Android Build Support
and clickNEXT
- Review the license agreements to begin downloading and installation of Unity
- After Unity has been downloaded and installed, the installs screen will show a tiny Android icon next to the version that was installed
After downloading and installing Unity, VSCode, and registering for a Unity account, you should be able to play your first Android application within the next 15 minutes.
- On the left-hand menu, select
Projects
then click on the blueNEW
button on the right, and choose the version you installed
- Select
2D
(default is a3D
project), choose your desktop as the location the project will be saved to (Unity will create a new folder), and click onCREATE
- Unity will take a few minutes to create your new empty project
- After your project is created, you will be presented with the working environment
- Don't worry about all the different windowpanes and menu options for now, just follow along with the instructions
We must configure Unity use VSCode as the external code editor
- Go to menu item
Edit
→Preferences...
→External Tools
- Change
External Script Editor
to where you installed VSCode (navigate to whereCode.exe
is located)
Our application will be a button that increments the number shown above it when pressed; we can do this in three simple steps
-
Create a Button
- On the bottom-left windowpane, right-click on
SampleScene
and selectGameObject
→UI
→Button
.
- Where is the button? On the bottom-left, double-click on
Button
and the top-left windowpane will zoom to where the button exists- Note: Just because you can't immediately see an object you just created doesn't mean it doesn't exist in the project
- We must manually drag the button in the top-left windowpane into where the white outline is
- This brings the button into the actual view you will see when using the program (this is simulated in the top-center windowpane with blue background)
- On the bottom-left windowpane, right-click on
-
Create Text Box
- On the bottom-left windowpane, right-click on
SampleScene
and selectGameObject
→UI
→Text
- If the text box doesn't appear within the white outline, click and drag it above the button
- On the bottom-left windowpane, right-click on
-
Create Script
- On the bottom-left windowpane, right-click on
SampleScene
and selectGameObject
→Create Empty
- On the bottom-left windowpane, left-click on the newly created
GameObject
- Details of the
GameObject
are seen in the right-hand windowpane, click onAdd Component
and in the small search bar, search for "script
", and click onNew Script
- Name this new script "
script
". Click onCreate and Add
- The script is now a component of the
GameObject
- We are going to double-click on this newly created script in the bottom-center windowpane and it will open in VSCode
- If this is your first time opening a file in VSCode, it may download some extras to help read the C# programming language that Unity uses
- Once all the extras are finished downloading and installing, click on the
X
button on the bottom windowpane
- Once all the extras are finished downloading and installing, click on the
- Unity will provide a default template for every new script:
- For now, just erase the default template code and copy-paste the code below and save (
CTRL+S
) the file:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class script : MonoBehaviour { public Button myButton; public Text myText; int myInt; void Start() // Start is called before the first frame update { myInt = 0; myButton.onClick.AddListener ( delegate { myInt += 1; myText.text = myInt.ToString(); } ); } void Update() // Update is called once per frame { } }
- Go back to Unity
- Unity will take a moment to process the code you just saved in VSCode
- Clicking on
GameObject
again, you will now see two new boxes appear in the right-hand details windowpane calledMy Button
andMy Text
(these were not here before you copy-pasted and saved the script above) - You must manually drag-and-drop from the bottom-left pane
Button
toMy Button
andText
toMy Text
- On the bottom-left windowpane, right-click on
-
Change the following two settings before playmode testing:
- Go to menu
Edit
→Preferences...
→Colors
and changePlaymode tint
to a dark red
- Select
Maximize On Play
so that other windowpanes are hidden during playmode
- Go to menu
-
You can start (and stop) playmode testing by clicking on the top-center ▶ (
Play
) button.
- Test your application by pressing the button and watching the number in the text box increment
- Stop playmode when you are done and make sure to save your Unity project
- Don't worry about design elements right now (font sizes, colors, etc.)
You're almost done; let's install this application on your Android device
- Go to menu
File
→Build Settings...
- Select
Android
on the bottom-left pane and clickSwitch Platform
on the bottom-right- Unity will take a few minutes to process this change
- Once done, the Unity icon will appear to the right of
Android
- Once Unity has been changed to build to the Android platform, click on
Build
- Navigate to your project folder, name your file "
test.apk
", and save the application- Unity will take a few minutes to build your application to be ready for Android installation.
- Now you have the
test.apk
file needed to install your application on an Android device
- Connect your Android phone to your computer to transfer the
test.apk
file over- You may have to change the USB connection type to
Media (MTP)
in order to move files from your computer to your phone - Through File Explorer on your computer, copy and paste
test.apk
on your phone (I made a folder named "Unity
" to paste it into)
- You may have to change the USB connection type to
- Once the file transfer is complete, you can disconnect your phone from your computer
- Android should already have a program named
File Manager
or similar for you to explore files on your device - Navigate to where you placed
test.apk
on your phone, click on it to install
WARNING: You should NEVER install unverified applications on your Android phone unless you have made them yourself and are confident they are safe
- By default, Android will prevent you from installing applications from unknown sources, we will temporarily allow this just to install our application
- Install will be blocked but you can click on
Settings
to go toSecurity Settings
- Once in
Security Settings
, go underPhone Administration
and click on the checkbox forUnknown sources
- A pop up will appear and click on
Allow
applications from unknown sources (in this case, this is the application you just made)
REMEMBER: After the tutorial, come back to Security Settings
to change this back to blocking application installs from unknown sources
- Press the back key to go back to File Manager and click on
test.apk
andINSTALL
on the bottom-right again. - When the window about Play Protect pops up, select
INSTALL ANYWAYS
- Another popup window will ask for Play Protect scanning, you can click on
DONT SEND
- After a few moments, your test.apk is now installed as "
New Unity Project
" - Click on
OPEN
on the bottom-right to launch your application
- If you launched your application directly after installing, you'll get the Unity splash screen and then be presented with your application
- If you did not launch after install, find "
New Unity Project
" on your device
- If you did not launch after install, find "
- Tap on the button and watch the numbers increment!
- The button and text box may be tiny, but it should work
- Didn't like how small the button and text were? Make them larger.
- Want more buttons and text boxes? Make more!
Now that you have a feel for the workflow of using Unity, the possibilities are endless
- Design innovative and fun games
- Master the C# programming language
- Make productivity apps to help you succeed
Clean Up
- If you make changes to this application, you should uninstall the current version first before installing the updated version
- On your Android device, go to
Settings
→DEVICE
→Apps
, find and select "New Unity Project
" and click onUninstall
- On your Android device, go to
- You may want to erase the
test.apk
you made or start numbering these files with some sort of versioning system as you make changes, e.g.test_V2.apk
ortest_2019-12-08.apk
REMINDER: Go back to Security Settings
to change back to blocking application installs from unknown sources
Issue | Solution |
---|---|
Where is the button/menu item/etc.? | There may be major differences between versions of Unity: if you upgrade in the middle of development, you could break your application |
I made some changes in Unity but it didn't seem to "Save" them | Any changes when Unity is in "Playmode" are not saved; make these two changes in the 4. Playmode Test section to ensure that doesn't happen |
- Q: Why are we developing in Unity for an Android application, couldn't we have just used Android Studio?
- A: Unlike Android Studio, a Unity project can also be built for iOS, PS4, Xbox One, Windows, MacOS, etc.
- You will frequently go back and forth between manipulating objects in the Unity's graphical user interface and programming in Visual Studio Code
- Consider having devices that are solely for testing that are not linked to your social media, email accounts, cellular SIM card, etc.
"Unity is.. peculiar..."
Veteran software engineer colleague learning Unity
- This tutorial was developed on Microsoft Windows 10, Unity 2019.2.15f1, and Visual Studio Code 1.38.1
- Different versions of Unity may have slightly different menu placement, menu names, etc.
Description | Link |
---|---|
Official Unity Tutorials (Free) | https://learn.unity.com |
GameDevTV 2D Unity Course (Paid) | https://www.gamedev.tv/p/complete-unity-developer-2d |
Official Unity Terms of Service (Unity is free until you start making money) | https://unity3d.com/legal/terms-of-service/software |
Copyright © 2019-∞ Athit Kao, Terms and Conditions