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 - positioning and scaling the clock

The pie clock is pretty neat, but it's sadly stuck to the top-left corner of the screen. It would be great if we could make it any size we wanted, and if we could move it anywhere on the screen.

We're not far off from that goal. Follow these steps to get a dynamically positioned and scaled pie clock:

  1. Create these variables at the top of the OnGUI function:
    var pieClockX:int = 100;
    var pieClockY:int = 50;
    var pieClockW:int = 64; // clock width
    var pieClockH:int = 64; // clock height
    var pieClockHalfW:int = pieClockW * 0.5; // half the clock width
    var pieClockHalfH:int = pieClockH * 0.5; // half the clock height
    

    In this example, 100 and 50 are the X and Y values where I'd like the pie clock to appear ...

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