Unity Evolution 46 Million Quartet
The life of a planet starts at the beginning of its birth, and will witness the rise and fall of countless civilizations, the birth and extinction of species, under countless natural disasters and earth changes, nothing is eternal, only the constant change of itself , Continuous evolution in adversity can achieve perfect victory. The story will start with a small program...
Opened a new pit~~(opening the pit and filling the crematorium for a while)~~, Javaweb
there is a limit, I choose to go Unity
! It can be regarded as fulfilling my original intention of learning programming at the beginning. The previous web articles are not expected to be updated (although they haven’t been updated in half a year). In the follow-up, there will be more andSpringBoot
articles for the completion of the project. The current idea is to make a three-year college. Throw it on.VUE
个人网站
The purpose of opening this pit is to witness the evolution of one's own technology. Taking time as a ruler and the past as a book, I think it will be very emotional to see these after a few years.
这次绝对一直更下去!
Chapter 1. The first cell (Roll_Ball)
How to download Unity Install Unity Use Unity I won’t go into details, there are a lot of them on the website
The introduction of this example is that in a scene, the sphere controlled by the player collides with the small cube representing the points. After the collision, the small cube disappears and the points accumulate for one point. When the points reach a certain number, the player wins.
1. Initialize the game environment
- Put the game scene you want through the following 3D objects
Create Materials (material folder) in Project, right-click to create a new material, select your favorite color and drag it to the object to achieve color change
create points预制体
(1). Put a copy of the prefab into the scene, this process is instantiation.
(2). The instantiation of the prefab is not an ordinary copy. The new game object generated after the prefab is instantiated still maintains the association with the prefab, that is, the prefab is added components, modified properties and other operations, and the game object after the prefab is instantiated will change accordingly.
2. Control the movement of the ball
-
To move an object, first of all, the object can be in contact with the bottom surface, so it is necessary to add a ball to the ball
刚体组件(Rigdbody)
-
Secondly, we need to give the ball the force to move through the code, create the PlayerMove code and drag the code to the object component you want to control.
Write code
3. Camera Follow
After the above two steps, the ball should be able to move successfully, but our camera is still fixed, so we need to move the camera to follow the ball so that the ball is always centered in our field of view.
-
Position the camera so that the ball is within your line of sight
-
Write follow player code
4. Display text
For this game we need at least two texts one is and 积分的文本
one is胜利的文本
Right-click in the game directory Canvas
to create a new Text
text
The text can be whatever you like
Pay attention to the text of the game victory, we need to hide it, just tick the check box in the upper left corner
5. Integral detection
Unity provides us with three detection methods 碰撞检测
射线检测
and what is needed for this project触发检测
Because we need the integral model to disappear directly when the ball hits the integral, we choose to trigger detection for detection. In the case of collision detection, the ball will pause at the moment when the ball and the integral collide because of the rigid body, which is not beautiful.
-
Write the following code in the script of the previous ball movement
The OnTrigger function has three types representing three states Just contact (Enter) Contact (stay) Exit (exit) Here we use the first contact trigger
I believe you have also noticed this judgment condition other.gameObject.name is to get the name of the touched object
other.tag is to get the tag of the touched object, here we use the tag to trigger, because the object to be triggered is the same type of object
-
new label
-
Just drag the points text and victory text into it
6. Package and run
Well, I believe you have successfully manipulated the ball
Let's do the last step to package and publish the game you made on the Windows platform so that you can start it directly from windows!
-
Enter the packaging interface
-
packaging settings
Note that the scene in Scenes In Bulid must be your game scene
-
After the setting is complete, click Bulid to select the corresponding folder to package
-
packing finished
After the packaging is complete, a dialog box will pop up. The files in it are all the files you output. If you delete any file, it will cause the game to run incorrectly.
-
run
Click the .exe file with the file name you set to enter the game
-
Play!