O'Reilly logo

Unity 3D Game Development by Example by Ryan Henson Creighton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - write 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:

  1. Knowing when the clock has passed the halfway point is pretty important with this clock. Let's create an isPastHalfway variable inside our OnGUI 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).

  2. Define a rectangle in which to draw the textures:
    var isPastHalfway:boolean = percent < 50; var clockRect:Rect = Rect(0, 0, 128, 128); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required