Simple strips of blood from unity

Source: Internet
Author: User

There are many ways to make blood bars in unity, most with Ngui; here I'll talk about a simple method of making blood strips.

This blood bar production is not like Ngui, it is by a piece of code can be achieved, but looks less effective, or look at the code bar;

 public texture2d bg;     //the background of the blood bar, you need to drag and drop the assignment outside; public  texture2d blood;   //Blood Bar  float Life=100;             //Total health value;   public transform m_transform;  // A transform component of an object bound to a blood bar;   void ongui ()  {    vector3 headpos= Camera.main.WorldToScreenPoint (m_transform.position+vector3.up*2.5f);    //converts a point on the object's head to screen coordinates;     gui. Drawtexture (New rect (headpos.x-15,screen.height-headpos.y,100,3), BG);                //the background of the blood bar is finished, the blood bar on the screen position    gui. Drawtexture (New rect (headpos.x-15,screen.height-headpos.y,100*life/life,3), blood);    // (HEADPOS.X-15,SCREEN.HEIGHT-HEADPOS.Y)                                                     //the Blood bar is 100 units long, 3 units wide, so you should read it.;                                                           //Current Health value/Total Health = current blood bar length/background length  }

This will be OK, the code I am directly in the face of the writing, there is a wrong words welcome correction Oh!

This article is from the "51cto_king" blog, make sure to keep this source http://cjboking.blog.51cto.com/11020113/1784372

Simple strips of blood from unity

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.