Unity Basics — Adding an Asset to our Scene, Renaming and Adding Scripts

Objective: Add an asset to our scene, rename the object and a script to it

Adding an asset to our scene

To get you started, let’s add a cube to our scene (which we are going to give movement to) by right clicking in the Hierarchy window → 3D Object → Cube. This will have instantiated a cube in our scene and sometimes it might randomly not be in the middle of your screen (don’t stress!). To change this look at the below image and change our cubes transform position on the X, Y and Z axis to 0, 0, 0.

Setting our cubes transform position to zero

Renaming our asset

We are also going to rename our cube to Player. We have a couple ways to do this, the first is by right clicking on the cube and pressing ‘Rename’ and you will see in the Inspector panel that it updates also. The other way is changing it in the Inspector panel and it will automatically change in the Hierarchy. Both ways work the same!

Renaming our asset

Adding a script to our asset

Now we need to add a script to our Player to get them moving. We are going to right click in the Project window → Create → Folder. Name this folder ‘Scripts’. Right click on the scripts folder and Create → C#Script. Name this ‘Player’. Double click on this to open it. Depending on which IDE you have setup as default with Unity, it will open in this. For this guides purpose we will be using Visual Studio 2017.

Adding a C# script to our project

Once you have created your script, drag and drop it onto the ‘Player’ game object as shown below to add the script.

Drag Player script onto the Player game object

An alternative approach to the above, you can click on the ‘Player’ game object and within the Inspector panel we can add a component as shown below. Don’t forget to drag the ‘Player’ script into the Scripts folder to keep your project assets nice and tidy.

Adding a script to our game object through Add Component



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