Time for action – writing the pie chart script
With these Texture2D
variables defined, and the images stored in those variables, we can control the images with our script. Let's lay down some code, and pick through the aftermath when we're finished:
Because of the switcheroo we have to pull off with the two yellow half-moon pieces, knowing when the clock has passed the halfway point is pretty important with this clock. Let's create an
isPastHalfway
variable inside ourOnGUI
function:function OnGUI () { var isPastHalfway:boolean = percent < 50;
(Confused? Remember that our
percent
variable means "percent remaining", not "percent elapsed". When percent is less than 50, we've passed the halfway mark).Define a rectangle in which to draw the textures:
var isPastHalfway:boolean = percent < 50; var clockRect:Rect = Rect(0, 0, 128, 128);
On the next line, draw the background blue texture and the foreground shiny texture:
var clockRect:Rect = Rect(0, 0, 128, 128); GUI.DrawTexture(clockRect...