What Is The Mohs Hardness Scale For Oklahoma Stone?

When choosing an Oklahoma stone for your residential or commercial project, it is crucial to be mindful of its characteristics and how they could impact your project. These details are necessary…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Lets get moving

Today we’ll be going over some basic movements, along with a couple quality of life processes.

Depending on the type of game you are looking to make, sometimes we need to adjust the background. All we simply have to do it switch to our main camera and under clear flags, we change it to solid colour and choose whatever colour will work best.

Colour change

Something else we should do early on is adjust the aspect ratio so that we can put it on any device we desire. What we typically want to choose is a 16:9 ratio, as it is a standard HD aspect ratio.

Now we are going to get started on making our scripts for the player. First, we will want to make a new folder in the project view under assets and name it as Scripts. From here, we can make a new C# script, and name it player.

When naming your script, it is important to be sure to name it when you make it originally, otherwise you could run into some issues later. When we click on the script in the projects tab, it will show what is within the script, and here we can see that the public class is player.

If we were to forget to name it right away and do so after the fact, the public class will be different. What will happen is Unity will give an error when using the script.

Now we get to start to get into the nitty gritty part of it, using scripts. To start, we will just start with some basics, but as things go along, there will be a lot more to it.

As we can see from the image above, there isn’t much within the scripts to start.

public class Player : MonoBehaviour → This is a Unity specific term that is used to allow us to drag and drop the script onto our objects. The “:” stands for inherits or extends. If we wanted to make custom classes, we just have to delete the “: MonoBehaviour”.
void Start() → This is a method that is automatically called from Unity when you start the game.

void Update() → This is a method that is considered a game loop and typically runs at 60fps, and what we put in there will run every frame, unless we restrict it otherwise.

// → We type this within the script to make comments, or notes for ourselves. This will not run in Unity, but is merely a type of notepad we can use for future reference.

If we want to set a position for an object, the line of code that is used is rather simple.

One thing that we should get into a habit of, unless you have used the specific line of codes more times than you can count, is to read the tooltip to know what the specific line of code you are writing will do.

As you can see above, this 1 line of code will create a starting position for the player. As for the code itself, transform.position is telling Unity what you wish to have to information pertain to. The “new Vector3” is used to set our desired position. Vector3 is for the position of the object on a 3D space. The (0, 0, 0) is designating the player object along the (x, y, z) axis.

A key thing you will always want to remember is that when you are finished with a line of code, you always, always, always end it with ;. This lets Unity know that the line has ended and it isn’t continuing on. If you have forgotten to place the ; then you will have an error message and red lines under the affected area.

Example of missing ;

If we were to be creating a game with a teleport effect, this would be the method we would use as well. All we are doing is telling Unity to change the position of our object to the desired one.
Now, if we wanted to see if what we did works, we have to be sure to attach our script to the player object and press play.

Showing change in position

As we can see from the example above, when we press play, the position of our player object will change to our set location.

In order for us to start getting some movement going, we got to learn how to research for what script we need to write. With Unity, we can easily access the manual and all scripting API available to us.

To open up the documentation, simply click on the small ? to open up the site for all the information. Then, switch to Scripting API and type what you are searching for. In this case, we are looking at changing the transform of our object, so once we search for Transform, we then go down to Translate, which is to move the transform. From there, we can see the script structure we need to use.

As you can see, we used the structure from the manual and applied it to our script. We type (Vector3.right) to tell Unity that we want our object to move to the right.

Now that we have movement, we will have to figure out how to change the speed, allow user input rather than it moving on it’s own and have a boundary set so that we stay within the game screen. Join me next time as we figure out how to apply all of these scripts to our project.

Add a comment

Related posts:

MOTHER DOG REVIEW

In this age of globalization, time is of the essence for everyone. At this time that digital currency has been introduced to reduce transaction time. The cryptocurrency was originally known as a…

5 tips voor teams die plotseling thuis werken

Op dit moment kunnen we allemaal wel wat extra hulp gebruiken. Covid-19 heeft het nieuws overgenomen, de aandelenmarkten storten in en supermarkten worden geplunderd. Overheden van over de hele…

Create a simple pie chart with SwiftUI

When we want to display statistical information, it is better to display data in graphic forms like charts and graphs. Pie chart is the most common of these because it is simple and easy to…