1. Loop progress bar
2. Graphics matching
Using unityengine;using system.collections.generic;using unityengine.ui;///<summary>///dragged large square///</ Summary>public class Dragbrick:monobehaviour {private list<transform> Childrentra = new LIST<TRANSFORM&G t; ();//small square under the generous block private list<gameobject> Targetgo = new list<gameobject> ();//small square matching empty box private Gameobjec T[] TEMPGO; Private Vector3 Posoffset; void Start () {transform[] tra = Transform. Getcomponentsinchildren<transform> (); for (int i = 1; i < tra. Length; i++)//tra[0] is itself, therefore does not count on Childrentra.add (Tra[i]); } public void DragStart () {posoffset = transform.position-input.mouseposition; Transform. Setaslastsibling (); } public void Dragupdate () {transform.position = input.mouseposition + posoffset; }///<summary>/////1. The object to be detected by the Ray should be collider///2. The z axis of the object being detected by the Ray > the z-axis of the object that emits the ray detection//3 When the Layermask parameter is not passed to the Raycast function, only the use of IGNORERAYC is ignored.The collider of the AST layer. </summary> public void Dragend () {tempgo = new Gameobject[childrentra.count]; int suitablebrickamount = 0;//can correctly match the number of bricks for (int i = 0; i < Childrentra.count; i++) {Raycast Hit hit; if (Physics.raycast (Childrentra[i].position, Vector3.forward, out hit)) {Tempgo[i] = Hit.transf Orm.gameobject; suitablebrickamount++; } else break; if (Suitablebrickamount = = childrentra.count)//exact Match {if (Targetgo.count = = 0)//first exact match {Match (); } else//has been fully matched and again exactly matches {Clear (); Match (); }} else//cannot exactly match {Clear (); }} void Match () {for (int i = 0; i < tempgo.length; i++) {Targetgo.add (tempgo[i]); Targetgo[i].layer = 2;//ignores ray collisions Vector3 pos = targetgo[i].transform.position; pos.z--; Childrentra[i].position = pos; Childrentra[i]. Getcomponent<outline> (). Enabled = TRUE; }} void Clear () {for (int i = 0; i < Targetgo.count; i++) targetgo[i].layer = 0; Targetgo.clear (); for (int i = 0;i < childrentra.count;i++) Childrentra[i]. Getcomponent<outline> (). Enabled = FALSE; }}
3. Multiple blood Strips
Describe:
1. The "residual blood" effect occurs when the damage is small
2. When the damage is greater, the "running water" effect appears
3. Multiple blood strips consist mainly of four blood strips:
A. Bottom-level blood strips
B. The current blood bar and the next blood bar, like purple and red in the
C. Transitional blood strips, generally dark red
Using unityengine;using system.collections;using Unityengine.ui;public class Bossbloodbar:monobehaviour {public Imag e Nowbar; Public Image Middlebar; Public Image Nextbar; Public Text Counttext; private int count;//Blood bar number private float nowblood;//The current amount of blood in a blood, such as: 100/1000 is the private float Onebarblood = 1500f;//a blood capacity, such as: 100/1000 is the $ private int colorindex; Public color[] colors;//the color of the common blood bar, note the color of the alpha value public color middlebarcolor;//transition Bar, note the alpha value public float Slowspeed = 0.1 F;//is seriously injured (>onebarblood) or in the state of blood, the normal flow rate of public float quickspeed = 1f;//received minor injuries (<onebarblood), the flow rate of ordinary blood bar Priva Te float speed;//The speed of public float middlebarspeed = 0.1f;//transition Bar flow speed private float Targetbloodvalue = 1f;//Blood Bar Move the target point private bool Isbloodmove = false;//Control The movement of the Blood Bar void Update () {movebloodmiddle ();//flow of the transition bar Moveblo Odnormal ();//flow of normal blood bar}///<summary>/////////</summary>/////<param/////Name= "number" > </param> public void Initblood (float number) {count = (int) (Number/onebarblood); Nowblood = number% Onebarblood; ColorIndex = count% colors. Length; Nowbar.color = Colors[colorindex]; Nowbar.fillamount = Nowblood/onebarblood; if (count! = 0) {int nextcolorindex = (colorIndex-1 + colors. Length)% colors. Length; Nextbar.color = Colors[nextcolorindex]; } Middlebar.color = Middlebarcolor; MiddleBar.gameObject.SetActive (FALSE); Counttext.text = count + ""; }///<summary>///Blood volume changes, and according to the injury to determine whether to use the transition bar///</summary>//<param name= "number" ></param& Gt public void Changeblood (float number) {Nowblood + = number; Targetbloodvalue = Nowblood/onebarblood; Isbloodmove = true; if (number < 0) && (mathf.abs (nowbar.fillamount-targetbloodvalue) <= 1)//is in an injured State and the amount of damage is low { Speed = Quickspeed; MiddleBar.gameObject.SetActive (TRUE); Middlebar.fillamount = Nowbar.fillamount; Targetvalue = Targetbloodvalue; } else {speed = Slowspeed; MiddleBar.gameObject.SetActive (FALSE); }} private float Targetvalue; void Movebloodmiddle () {if (speed = = quickspeed) {Middlebar.fillamount = Mathf.lerp (Middleba R.fillamount, Targetvalue, middlebarspeed); if (Mathf.abs (middlebar.fillamount-0) < 0.01f) {MiddleBar.transform.SetSiblingIndex (nextba R.transform.getsiblingindex () + 1); Middlebar.fillamount = 1; targetvalue++; }}} void Movebloodnormal () {if (!isbloodmove) return; Nowbar.fillamount = Mathf.lerp (Nowbar.fillamount, targetbloodvalue, speed); if (Mathf.abs (Nowbar.fillamount-targetbloodvalue) < 0.01f)//reach target point isbloodmove = FALse if (count = = 0) nextBar.gameObject.SetActive (false); else nextBar.gameObject.SetActive (true); if (Nowbar.fillamount >= targetbloodvalue) Subblood (); else Addblood (); } void Addblood () {Float subvalue = mathf.abs (nowbar.fillamount-1); if (Subvalue < 0.01f)//arrival 1 {count++; Counttext.text = count. ToString (); Nowbar.fillamount = 0; Targetbloodvalue-= 1; Nowblood-= Onebarblood; Nextbar.color = Colors[colorindex]; colorindex++; ColorIndex%= colors. Length; Nowbar.color = Colors[colorindex]; }} void Subblood () {Float subvalue = mathf.abs (nowbar.fillamount-0); if (Subvalue < 0.01f)//Arrival 0 {MiddleBar.transform.SetSiblingIndex (NextBar.transform.GetSiblingIndex () + 2); if (count <= 0) { MiddleBar.gameObject.SetActive (FALSE); Destroy (this); Return }; count--; Counttext.text = count. ToString (); Nowbar.fillamount = 1; Targetbloodvalue + = 1; Nowblood + = Onebarblood; colorindex--; ColorIndex + = colors. Length; ColorIndex%= colors. Length; Nowbar.color = Colors[colorindex]; int nextcolorindex = colorIndex-1 + colors. Length; Nextcolorindex%= colors. Length; Nextbar.color = Colors[nextcolorindex]; } }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
[Unityui] Some interesting UI examples