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 ...

Get Unity 4.x Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.