[Unity3d] Unity3d and the effect of skill cooling on Ngui's blood strips

Source: Internet
Author: User


--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------

Like my blog Please remember my name: Qin Yuanpei , my blog address is Blog.csdn.net/qinyuanpei.

Reprint please indicate the source, this article Qin Yuanpei , this article source: http://blog.csdn.net/qinyuanpei/article/details/40744781

--------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------

Dear friends, Hello everyone, I am Qin Yuanpei, welcome to pay attention to my blog, my blog address is Blog.csdn.net/qinyuanpei. After the completion of all the courses in November, it means that Bo mainly began to look for work, because Bo Master is non-computer professional background, so first to complete the professional internship, so bloggers this period of time are busy looking for internship units. In the process of looking for internship units, more or less contact with some of the enterprises from the traditional industry to the Internet industry, bloggers in the internet industry has a profound impact on all walks of life at the same time on the nature of the industry to think. The internet industry is a kind of service industry with technical attribute, media attribute and social attribute, which connects people and people, people and information, information and information by providing people with various services. The internet industry is now more and more than an industry, but it is more and more like a society, the successful internet business model will eventually be in a link to the real world, so the internet industry is not the technology to win, but it is found a better way to the virtual world and the real world link up. Probably because of the long-term research technology to form a fixed mode of thinking, Bo Master has always been that technology is the core of the Internet industry, so once reading Li's "Silicon Valley Business" this book, Li in this book "Technology is not the only decisive strategy, business strategy is the key to winning thousands" This view is not very agreeable, but at this time the blogger is deeply aware of this, there is faith, have feelings, there is technology can let you do a good job, but if you want to make a thing, you need to consider a variety of factors. Because the internet industry is facing the end user is people, as long as the people, then in the traditional industry problems will encounter, even if you like to stay at home, even if you do not like to deal with people, the problem is always to face. Well, let's start with the question here, we're going to use Ngui to achieve the blood bar and the skill cooling effect today. First, let's look at the effect we're going to achieve today:


From this demo we can find the specific content to be implemented today is the game interface GUI Blood bar and the monster head of the blood bar and skill cooling effect of the realization, we here will be divided into blood and skills to cool two parts to explain, I hope to learn Ngui some help, if there are shortcomings, I hope we can understand.


First, the Blood bar

In the previous article bloggers have shared with you the use of Ngui in Unity3d content, then today we will continue to learn how to use Ngui in the Unity3d to achieve blood bar! It is very simple to implement a blood bar in the Unity3d. In the blog before the article "Unity3d Game development 2D Map to achieve the blood bar assembly," the blogger introduced and implemented a 2D map based on the Blood Bar assembly, the principle of the method is stacked before and after displaying two different map foreground map and background map, by changing the width of the foreground map can achieve the effect of the blood bar. In Ngui, slider is such a control, so we can use sliders to achieve the blood bar effect. First we create a slider control in the scene,


So we can use the Ngui to make a beautiful blood bar effect. Next, we repeat this work 3 times, and finally we can design the effect to come out:


The entire UI is made up of a background image (Sprite) and three sliders so that we can build the interface in the game. The slider control has one of the most important property values called Slidervalue, which is a numeric value between 0 and 1 that represents the length of the slider in the slider as a percentage of the total length, and we use this property value to show the amount of blood in the bar. For example, we will the total amount of the player's blood is 100, then the player's blood volume percentage is the player's current amount of blood and total blood ratio, we just assign this value to the slide control of the Slidervalue can be. For example, we can use the following code to indicate that the player has lost blood:

This. Hpvalue=this. HPValue-10; Hptrans.getcomponent<uislider> (). slidervalue= (float) this. hpvalue/100;
Here Hpvalue as the name implies is the current blood volume of the monster, Hptrans is the Blood Bar (Slider) where the transform. In the actual design, the total blood volume of the monster varies depending on the level of the monster, so we'd better keep the total amount of blood in the archive or database so that we can make the blood bar vary depending on the amount of blood the player has. As you can see in the previous demo, the player will have less blood when attacked by a monster. Now that we've mentioned the decrease in blood volume, let's just say, by the way, automatic back-up, automatic return to blue in some games. For example, in "Gujian Tan 2" game, because the combat mode was changed to the instant system, so the player in the game "Chi" no longer rely on by attacking the enemy in the battle to obtain, but when the player in the idle state slowly recover. Since the player is suffering from blood loss will reduce the amount of blood, then automatic recovery will naturally increase the amount of blood, which we do not say.

Let's talk about how the blood bars in the monsters ' heads are implemented in the game, right? Unlike the bars in the GUI, the blood bars on the head of the monster move with the player's movement. Here we first introduce two concepts, the bulletin Board (BillBoard) and the HUD (head-up display device).

A notice board is simply a quadrilateral or planar face in the scene, which is always aligned with the direction of the camera's gaze. What can bulletin board technology be used for? Bulletin board technology is used in the game from GUI to cue messages in the game, tree rendering in the scene, and so on. For example, when we play the classic CS game, when the player presses the E key can be the demolition of bombs, the game interface will prompt players related operations, which is a notice board technology application scenario. In addition, in the early 3D games, the trees in the scene are usually in the form of a plane (paper), which can effectively reduce the number of rendering in the game, but this will reduce the performance of the game, which is played by bloggers in the "Paladin three" and other games to make more common.

And the head-up display device is a game term derived from the military field, it can be the game-related information in an intuitive way to display on the game screen, without affecting the player's normal view content, so that players can always know the most important and directly related content. Head-Up display device Common application scenarios are: RPG game life, Magic, state, line power, and act game statistics, scoring, wonderful shots, combos and so on. The reason for mentioning these two concepts here is that their technical implementations are similar, and basically involve conversions of 2D coordinates and 3D coordinates. The blood bar above the monster's head needs to convert the 3D coordinates in the Unity3d to 2D coordinates, then converts the X-y coordinates to the 3D coordinates used under Ngui. Specifically, we can refer to Xuanhusung's Article Ngui Research Institute of 3D Model coordinates to 2D screen coordinates-blood bar. So, how do we do it here? We can use Ngui to make a pre-fabricated piece of blood bar, then hang it somewhere on top of the monster and make sure the blood bar on the top of the monster is always facing the main camera. This is quite simple in Unity3d:

Hptrans.lookat (Camera.main.transform.position);
In this way, the Monster Blood Bar will be based on the distance from the camera and show the different proportions of the size, Bo Master think the effect is pretty good ah, hehe. Well, the sister is again a group of small strange to siege, I am very cruel ah ...





Second, skill cooling

Skill Cooling is a concept that appears after the emergence of real-time games, especially in World of Warcraft. The so-called skill cooling refers to the time from the last skill use to the beginning of this skill, namely the skill CD. A visual example of this is that if a skill's icon is fully lit in the game interface, it means that the skill is cool, otherwise it is cooling, and only after the skill cooldown can we use the skill again. We use "Gujian Tan 2" as an example to explain the skills of cooling, the game is the actual battle screen


"Gujian Tan 2" from the game's production concept for the first time to break through the domestic single-game turn system of the pattern, must say is a domestic single-game production history of a major breakthrough. You can notice that the skill bar at the bottom of the screen, the skills in this skill bar are now in the cooling state, so the player is not able to use these skills at this time, only after the cooldown of the skill can be used. Mention of "Gujian Tan 2" battle, Bo Master still can't help to vomit trough, first skill too procrastination, the player had to stop to wait for the protagonist in the game to play a set of actions, and more people are not able to interrupt the skill to stop the skill, So when playing this game blogger most of the time in a state of Chaos (laughter), but listen to the weapon and the enemy stirred together the sound of the voice Bo Master feel that playing the dance is also a good choice ah, haha. Okay, no kidding. Let's take the skill cooling effect in Unity3d as an example to explore the ability to cool, first of all, we first understand the principle, the ability to achieve the effect of cooling effects need two Ngui control to implement, that is, Sprite and Filledsprite two controls. Where the sprite control is responsible for displaying the skill picture, the Filledsprite control is responsible for displaying the skill mask. Skill mask We just need to select a gray or black picture and set a certain amount of transparency. What is the benefit of filledsprite controls that allow images to be populated in a certain way? For example, in many games, the cooldown of the skill can be filled from the bottom of the skill picture or the clockwise/counterclockwise direction at a certain speed. So, we can use Filledsprite to implement this requirement. Here's a look at the specific approach:


Next we wrap the skill icon and mask with an empty game body, where we make three skill icons and set the opacity of the mask layer image to 150. Well, let's take a look at the Filledsprite this control, we notice that it has an important parameter fill dir that is the fill direction, where we can change this value to achieve different fill effects, we choose clockwise


360-degree padding. In addition, here is a fillamount parameter that represents the scale of the fill, which is a value between 0 and 1, which represents a full fill when the value is 1, that is, the entire mask layer is displayed, at which point the skill is being cooled, and the value 0 indicates no padding, that is, the entire mask layer is transparent, At this point the skill cooldown is complete. Based on this principle, we can easily implement the following script:

If not in the cooling state, enter the cooling if (!isskillcooling) {ui_skillmask.fillamount=1;isskillcooling=true;} If it is cooled, start the timer if (isskillcooling) {ui_skillmask.fillamount-= (1.0f/skillcooltime) *time.deltatime;if (ui_ skillmask.fillamount<=0.01f) {ui_skillmask.fillamount=0;isskillcooling=false;}}
Let's take a look at the actual effect:


We can note that the skill cooling effect basically comes out, but we need not the skill bar over and over again, we hope that when the skill is cooled, when the player presses certain keys or click on the skill icon to achieve the corresponding skills, when the player releases skill technology, the skill bar restart cooling, based on this idea, On the basis of the first script we have the improved code:

Using unityengine;using System.collections;public class Cdskill:monobehaviour {//skill cooldown 2.0spublic Float skillcooltime=2.0f;//Player release skill time private float mskillusetime=0;//skill length 1.5spublic float skilllength=1.5f;// Skill Cooling Mask Private Gameobject go_skillmask;private uifilledsprite ui_skillmask;//is in the cooling state private bool isskillcooling= False;void Awake () {//Get skill cooling mask layer go_skillmask=transform. Findchild ("Skillmask"). gameobject;//get Uifilledspriteui_skillmask=go_skillmask.getcomponent<uifilledsprite > ();//Bind a Click event Uieventlistener.get (transform.gameobject). Onclick=skillevent;} void Update () {skillcooling ();} void Skillcooling () {//If not in the cooling state enter cooling if (!isskillcooling) {ui_skillmask.fillamount=1;isskillcooling=true;} If it is cooled, start the timer if (isskillcooling) {ui_skillmask.fillamount-= (1.0f/skillcooltime) *time.deltatime;if (ui_ skillmask.fillamount<=0.01f) {ui_skillmask.fillamount=0;isskillcooling=false;}} if (mskillusetime<skillcooltime) {mskillusetime+=time.deltatime;} Else{mskillusetime=skillcooltime;}} void Skillevent (GaMeobject go) {if (mskillusetime==skillcooltime) {Debug.Log ("Add specific skill effects here");  mskillusetime=0;   Isskillcooling=false; }}}
Okay, so we're done with two things in today's article: Blood strips and skill cooling. Hope you like Ah, this period of time Bo master write code time really not much ah, because soon graduated ... Finally, everyone to enjoy the next blogger to do this little game! Special effects scenes of God horse, please ignore directly! ........



Daily Proverbs: The greatest opponent of man is not others, but his laziness. You have to do your best to be qualified to say you have bad luck.



--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------

Like my blog Please remember my name: Qin Yuanpei , my blog address is Blog.csdn.net/qinyuanpei.

Reprint please indicate the source, this article Qin Yuanpei , this article source: http://blog.csdn.net/qinyuanpei/article/details/40744781

--------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------

[Unity3d] Unity3d and the effect of skill cooling on Ngui's blood strips

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.