Unity3D Platformer Progress bar Tutorial 10

Advertisemen

Unity3D  Platformer Progress bar Tutorial 10







THIS IS Java scrip: GOOD 4 2D GAMES AND 3D GAMES !
----------------------------------------­­­­­------------------------------------­-­-­-­-­------



// set GUI bar width and height
var barWidth : float = 500;
var barHeight : float = 25;

// drag a texture as the icon
var progIcon : Texture;

// where to set the GUI element to
private var barProgress : float;

// empty objects represent the start and end of a
var startPoint : Transform;
var endPoint : Transform;

// current Player position
var playerPos : Transform;

function Update(){
 // get level distance by subtracting start and
 var totalDist : float = endPoint.position.x -
startPoint.position.x;

 // get player distance from start in X axis only

 var playerDist : float = playerPos.position.x -
startPoint.position.x;

 //get player's progress as a percentage of the
 var playerProgress : float = playerDist /
totalDist * 100;

 //turn the playerProgress percentage back into
 barProgress = playerProgress / 100 * barWidth;

}

function OnGUI() {
 //  width of the bar
 //  for 'Start' and 'End'
 GUI.BeginGroup (new Rect (250, 10, barWidth,
barHeight*2));

  //draw a box as the backing for the progress
  GUI.Box(Rect(0,0,barWidth,barHeight),"");

  // create a label to draw the progress icon
  // to set its X position, 0 as the Y position

  GUI.Label (Rect (barProgress, 0,
progIcon.width, progIcon.height),
        progIcon);

  // add start and end labels
  GUI.Label(Rect(progIcon.width/2, 1, 50,
barHeight),"Start");
  GUI.Label(Rect(barWidth-30, 1, 100,
barHeight),"End");

 GUI.EndGroup();
}


----------------------------------------­­­--------------------------------------­-­-­-

Advertisemen

Disclaimer: Gambar, artikel ataupun video yang ada di web ini terkadang berasal dari berbagai sumber media lain. Hak Cipta sepenuhnya dipegang oleh sumber tersebut. Jika ada masalah terkait hal ini, Anda dapat menghubungi kami disini.

Tidak ada komentar:

Posting Komentar

© Copyright 2017 Tutorial Unity 3D