How to load progress bar based on score increment or decrement

I am new to unity 3d and presently I am working on one island monkey project in which I decided to increment the score while drag and drop the item to land from menu and that time my score is increase and at the same time I decide to increase the progress bar base on level. I don’t no how to load progress bar.

So could any one help me for this problem.

1 Answer

1

It depends if you want a custom bar or a “just” a bar :1. Unity3d Tutorial - Health Bar 1/2 - YouTube here is for a bar using unity features.

Now if you want to have a custom bar with the shape and color you want, you need first to create them using Gimp or photoshop. You will have to draw a bar for each level of health. Then using a switch statement, depending on your health you draw a particular texture2D.

var health0 : Texture2D;
var health1 : Texture2D;
var health2 : Texture2D;


var HEALTH = 2;

function Update () { 	
	switch(HEALTH){				
		case 2:
			guiTexture.texture = health2;
		break;		
		case 1:
			guiTexture.texture = health1;
		break;		
		case 0:
			guiTexture.texture = health0;
		break;
	}
}

In this example I have 3 level of bar, full (2), half(1) or empty(0). You drag the 3 different textures in the inspector in the corresponding slot.

Now another script would alter my health and the value would decrease triggering a different case of the switch and showing a different texture on screen.

I saw you tagged c# but my example is in JS. Though it should not be too much hassle to convert.

ya ofcourse thanks

Hey here's a C# version free of charge! public Texture2D health0; public Texture2D health1; public Texture2D health2; public int HEALTH = 2; void Update () { switch(HEALTH){ case 2: { guiTexture.texture = health2; break; } case 1: { guiTexture.texture = health1; break; } case 0: { guiTexture.texture = health0; break; } } }