As we all know, numerical planning is the most important part in RPG Game planning. Numerical planning is a concept about game balancing. It is a very profound concept. In a sense, a game is a combination of multiple options. Therefore, if a game loses its balance, it will reduce the choice and affect the game's pleasure. Numerical planners usually need to adjust the related values of the entire game system to a suitable range according to certain rules and methods to ensure that players can have more options to enhance game playability. Numerical planning is a concept derived from the foreign gaming industry from the domestic gaming industry in recent years. In the process of learning game design, apart from focusing on technical implementation, we should also have some knowledge about the relevant theories in game design. For details about numerical planning, refer to http://baike.baidu.com/view/1756429.htm.
Next we will start today's unity3d skills training. We have learned the unity3d training goal: to allow U3D beginners to quickly master U3D technology, create and modify materials on their own, and develop small-scale 2D and 3D games and web games independently. Unity3d game development-damage value display ., It is a game called "blood rain: A mirage". Although this game is out of the previous two forms of integration, it enters the player's field of view again in the form of an act Horizontal Pass, however, I believe that only those who have really played this game know that this is a ground-based RPG Game. The strange and unique image style and the ancient martial arts Narration Style have brought infinite vitality to this evaluation. In recent years, the yuxue series is a rare game that has gained a great reputation abroad. This game is gorgeous in all ways, and it is a great blow. As a PRG game, the most important thing in the battle is the comparison of the life values of both sides of the enemy and me. Therefore, it is very important to show the damage that players cause to the enemy in real time in the battle. Legend of the legend. Now, let's continue with our unity3d learning journey. In the following article, we will use the ongui () method in unity3d to display the damage value.
Since it is based on the ongui () method, I believe everyone will be familiar with it, so let's give the code directly:
[CSHARP]View plaincopyprint?
- Using unityengine;
- Using system. collections;
- Public class damagepopup: monobehaviour {
- // Target location
- Private vector3 mtarget;
- // Screen coordinates
- Private vector3 mscreen;
- // Damage Value
- Public int value;
- // Text width
- Public float contentwidth = 100;
- // Text height
- Public float contentheight = 50;
- // GUI coordinates
- Private vector2 mpoint;
- // Destruction time
- Public float freetime = 1.5f;
- Void start ()
- {
- // Obtain the target location
- Mtarget = transform. position;
- // Obtain screen coordinates
- Mscreen = camera. Main. worldtoscreenpoint (mtarget );
- // Convert screen coordinates to Gui coordinates
- Mpoint = new vector2 (mscreen. X, screen. height-mScreen.y );
- // Enable Automatic Thread destruction
- Startcoroutine ("free ");
- }
- Void Update ()
- {
- // Make the text produce an offset in the vertical direction.
- Transform. Translate (vector3.up * 0.5f * time. deltatime );
- // Recalculate coordinates
- Mtarget = transform. position;
- // Obtain screen coordinates
- Mscreen = camera. Main. worldtoscreenpoint (mtarget );
- // Convert screen coordinates to Gui coordinates
- Mpoint = new vector2 (mscreen. X, screen. height-mScreen.y );
- }
- Void ongui ()
- {
- // Ensure that the target is in front of the camera
- If (mscreen. z> 0)
- {
- // Use GUI coordinates internally to draw
- Gui. Label (New rect (mpoint. X, mpoint. Y, contentwidth, contentheight), value. tostring ());
- }
- }
- Ienumerator free ()
- {
- Yield return New waitforseconds (freetime );
- Destroy (this. gameobject );
- }
- }
In the above Code, we need to grasp the following points:
1. Obtain the location coordinates based on the transform component and convert the coordinates into screen coordinates and GUI coordinates.
2. Four Common coordinate systems in unity3d:
A. World coordinates: Coordinates of objects in a scenario, obtained using transform. position.
B. screen coordinates: defined in pixels, the lower left corner of the screen is (0, 0), and the upper right corner is (screen. width, screen. height), the position of Z is measured by the unit of the camera's world. For example, input. mouseposition is the screen coordinate.
C. View coordinate: The view coordinate is standard and relative to the camera. The lower-left corner of the camera is (), and the upper-right corner is (). The Z position is measured in the unit of the camera's world.
D. Gui coordinate: the coordinate system is based on the (0, 0) Point in the upper left corner of the screen and (screen. Width, screen. Height) in the lower right corner ).
3. In the code, we first convert world coordinates into screen coordinates, and then convert them into GUI coordinates.
Now, we will bind this script to an empty game body and create a preset. In the following example, we will use this preset.
When the role attacks the red capsule, the damage caused by the player to the capsule is displayed in the game scenario. How can this problem be solved? We can add a collision tool to the model and capsule, and check istrigger to make it a trigger. We set their tags to player and enemy respectively. Next, write a script for enemy:
[CSHARP]View plaincopyprint?
- Using unityengine;
- Using system. collections;
- Public class enemy: monobehaviour {
- Public gameobject popupdamage;
- Void ontriggerenter (collider mcollider)
- {
- If (mcollider. gameobject. Tag = "Player ")
- {
- // Clone the injury pop-up component
- Gameobject mobject = (gameobject) instantiate (popupdamage, transform. Position, quaternion. Identity );
- Mobject. getcomponent <damagepopup> (). value = random. Range (20, 40 );
- }
- }
- }
Here we set the damage to the enemy to 20 to 40. Run the program and we will get the following results:
Because the exact collision is used here, the role of the program is collided with the capsule body at the beginning, while the ontrigger () method can only capture the collision at the beginning of the collision, therefore, only one damage value is displayed. Theoretically, only when a player attacks the capsule will the damage value display be triggered. However, we can ignore this issue because we are concerned with the display of the Damage Value. So far, this problem has been successfully solved.
Some may ask: why is the damage effect displayed in a game so dazzling, while your program can only display plain text? We provide two ideas for you to explore this question. The first method is to create a guiskin in the project, and then add a member variable of the guistyle type mstyle in the damagepopup script. With this variable, We can reference the guiskin created in the project. In this way, we can define the overall GUI style. In this case, modify the ongui method:
[CSHARP]View plaincopyprint?
- Gui. Label (New rect (mpoint. X, mpoint. Y, contentwidth, contentheight), value. tostring (), mstyle );
In this way, we can implement custom text effects. The second method is to use the texture, that is, first prepare a 0-9 digital image, then we extract the numbers on each digit of the value, and draw the Texture Based on the screenshot result, in this way, you can achieve custom results. Well, today's content is like this. For more exciting unity3d technical articles please click http://www.gopedu.com/article
Unity3d game development-damage value display