THIS CONTENT DOWNLOAD SHORTLY

Objective

Main objective of this blog post is to give you an idea about how to Making a Circular Timer using NGUI.

 

 

Step 1 Integrate NGUI

How to Create:

create-2d-ui

  • Next, take one sprite or texture as shown in the figure below.
 

Step 2 Scene Setup

selected

  • Set that texture or sprite type to ‘filled’ as shown in the figure.
  • Set Fill Direction to Radial360.
  • Now, take one GameObject and assign CircularTimer script to that object.

circular-timer

  • If you want to set circular progress bar to 10 seconds then assign 10 in max time variable (In this example it is 5).
  • Now, assign Texture in Timer texture variable if you have taken a texture else create script and take a variable of UISprite instead of UITexture and assign sprite to that variable.
 

Step 3 Code Sample

usingUnityEngine;
usingSystem.Collections;
 
publicclassCircularTimer : MonoBehaviour {
 
#region PUBLIC_VARIABLES
publicUITexturetimerTexture;//Timer Texture if There is a sprite and write UISpriteinsted of UITexture.
publicfloatmaxTime;//Max Time For Progress Bar.
#endregion
#region DELEGATES
#endregion
#region UNITY_CALLBACKS
voidOnEnable()
{
StartTurnTimer(maxTime);//Start When Object will Enable.
}
#endregion
#region PUBLIC_METHODS
publicvoidStartTurnTimer(floatmaxTime)//Call This Method When You Want to start Timer.
{
this.maxTime = maxTime;//Set Max Time.
StartCoroutine("StartTimer");
}
publicvoidStopTimer()//Call This Method To Stop Timer.
{
this.gameObject.SetActive(false);
}
#endregion
#region PRIVATE_METHODS
privateIEnumeratorStartTimer()
{
timerTexture.color = Color.green;
float i = 0;
float rate = 1 / maxTime;
while (i < 1)
{
i += rate * Time.deltaTime;
timerTexture.fillAmount = Mathf.Lerp(1, 0, i);
if (i > 0.75f)
timerTexture.color = Color.red;
yieldreturn 0;
}
}
#endregion
}

I hope you find this project very helpful while Circular Timer Using NGUI in Unity. Let me know in comment if you have any questions regarding Unity. I will reply you ASAP.

Got an Idea of Game Development? What are you still waiting for? Contact us now and see the Idea live soon. Our company has been named as one of the best Game Development Company in India.

I am professional Android App & Game developer. I love to develop unique and creative Games & Apps. I am very passionate about my work.

face mask Belial The Demon Headgear Pocket Staff Magic