Save you 3 hours to directly develop Unity's HelloWorld【Nanny level operation guide】

Inspired by a friend today: In addition to developing games, Unity can also develop animation effects and video recording.

It was very difficult for the school committee to make videos before. I heard that programming can be used to do it, and I immediately worked hard. It is estimated that I can better present the column of interesting stories and learning programming! That's it.

However, I have never used Unity, but as a multi-language enthusiast who has written Java for more than ten years, I don't think I should be stumped !

First look at the effect:

Save you 3 hours, to directly start developing Unity's first HelloWorld

Taking learning new knowledge as a challenge, I will start it below.

Install Unity

I use a MacBook Pro: the academic committee downloaded the 2017 UNITY LTS version

Why choose this?

Because it is installed through UnityHub (I installed the hub first), when installing, it prompts that about 14G of space is required to download Unity-related. Another friend showed that the development components for installing Unity 2020 also have more than 2G.

For the novice experience, you can actually choose a simple and easy-to-use one, why not have a light and fast one!

Come as fast as you can, download the 2017LTS version above.

The installation process is very simple. The only thing to pay attention to here is to select the license. Unity supports personal learning and use. Please remember to select 'Unity Personal'. The rest are easy to install in the next step.
The installation is very simple, pay attention to choose the Personal version to use

to develop

Create a new 2D project as follows:
insert image description here
After the project is built, the main interface is as follows:
First build a 2D project to see the main interface

This interface is distributed in the left, middle and right.

On the left is scene, shot, and component management.
In the middle is the visualization area, including the game simulation window.
On the right is the Inspector/Services column, which is mainly for finer control of Unity components.

Then the default below is: Project and Console
Project is to manage project files and resources.
Console is to run C# program to display debug log information.
As shown below (the school committee added an AudioMixer)
insert image description here

initial feeling

The school committee has only entered the beginner mode for a while, the following is my personal feeling, but please don't believe it all!

When I first entered Unity, I was confused. This thing is similar to AutoCAD/SolidWorks/3DMax modeling.
After groping for a while, I also feel that maybe Unity has more binding scripts and game rendering.

Compared to other development languages, Unity is like:

Learning Unity for the first time is like flying an airplane. There are many button components on it, and you can also program, but you need to be familiar with the operation of this thing, and it will be faster if you are familiar with it.

Otherwise, you will never find it no matter how long you spend! ! ! (collapse)

Learning Java/Python is like riding a bicycle, let you get on the car, and then add things on it, for developers, it is more about the exploration and expansion of the upper-level framework of the language, constantly pile up peripherals, and finally become rich in functions and catch up. The plane depends on its strength! (The game engine made by C++ is very good)

Okay, let's let go of the feeling first, and directly fumbled and read a part of the document.

Look at the operation below.

Operation focus

Add squares, circles, and text blocks to the main interface.
Only for the operation reference of the 2017 version
Add the Sphere (circle) and Quad (square) components.

The following figure shows the block components:
insert image description here

Bind code to the block

Select the square component (Quad) to enter the Inspector, then click Add Component in the lower right corner to add the script (bind our program code)
insert image description here
to enter Player, and then click "Create And Add":
insert image description here
After success, we see the following in the Inspector column:
insert image description here
Lazy people copy the following code into the Player C# script and save it:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//雷学委Unity小白初学demo
public class Player : MonoBehaviour {
    
    

	// Use this for initialization
	void Start () {
    
    
		Cursor.visible = false;
	}
	
	// Update is called once per frame
	void Update () {
    
    
	    //获取鼠标纵轴
		float y = Camera.main.ScreenToWorldPoint(Input.mousePosition).y;
		//让当前组件的坐标x轴保持不变,y轴跟者鼠标移动,也就是原地上下动。
		this.transform.position = new Vector3(transform.position.x, y, 0);
	}
}

insert image description here
As shown in the above picture, click the middle play arrow ➡️ button, and then look at the screenshot of the effect:
insert image description here

Key code analysis:

The knowledge in the screenshot below is the core interface MonoBehavior, this class is very important (link at the end of the article)!

This class is used to update the state of the component: that is, if we want to program the component to move from left to right, we have to look at this when jumping up and down.
insert image description here

Modify block color

Xiaobai can skip this operation!

On the right side of the screen, click Inspector->Materials -> Element 0, click the configuration button, and select the material of the block.
insert image description here

The final effect:

insert image description here

Summarize

This article is just the first experience of a developer who has never learned Unity, C# (it is Lei Xuewei himself) from installation to development, which is a good start! And starting from this article, you can save a lot of exploration time and directly copy the runnable code!

It is recommended for novices to read it, and remember to review it later when writing programs!

And readers, please be more patient. The picture below is an official LEGO (Lego) game. If you work hard, you will be able to win this crystal. Try again next time! There are more cool effects, here I suggest you learn a little bit first!
insert image description here
(PS: This official version is not compatible with the Unity version of the school committee, so this article does not choose the demo, because it needs to install 14.9G related software and it is estimated that it will take 3 hours to download)

Regardless of your programming ability, we will always be noobs in front of new knowledge.

So please keep learning with an open mind at all times so that you can make progress.
insert image description here

The installation and specific operation video will be updated later.

By the way, the academic committee still has this to pay attention to for long-term reading => Lei Xuewei's collection of interesting programming stories

Continuous learning and continuous development, I am Lei Xuewei!
Programming is very interesting, the key is to understand the technology thoroughly.
It's not easy to create, please support it a lot, like and bookmark to support the school committee!

reference link

I’ve seen this on w3c, the version is different, just looking for operation inspiration (some operation interfaces are indeed different): https://www.w3cschool.cn/unity3d_jc/unity3d_jc-fdk7380g.html
Unity2017 documentation:
https://docs. unity3d.com/2017.3/Documentation/Manual/class-SphereCollider.html
https://docs.unity3d.com/2017.3/Documentation/Manual/ScriptingImportantClasses.html

Guess you like

Origin blog.csdn.net/geeklevin/article/details/118750966