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 - commence operation pie clock

Let's lay down some code to make those half-circle pieces rotate.

  1. Set up a conditional statement so that we can draw different things before and after the halfway point:
    GUI.DrawTexture(clockRect, back, ScaleMode.StretchToFill, true, 0);
    if(isPastHalfway)
    {
    } else {
    }
    
  2. If we're not past halfway, rotate the GUI around the centerPoint. Draw the right side half-circle piece on top of the rotated GUI. Then, rotate the GUI back to its start position.
    if(isPastHalfway)
    {
    }
    else
    {
    GUIUtility.RotateAroundPivot(-rot, centerPoint);
    GUI.DrawTexture(clockRect, rightSide, ScaleMode.StretchToFill, true, 0);
    GUI.matrix = startMatrix;
    }
    
  3. Save the script and test your game. You should see the right side half-circle ...

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