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

Get Unity 3D Game Development by Example 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.