Tutorial to make Circular Timer without any " shaders and masking " in unity3d .
Step 1 : Requirements
Step 1 : Requirements
- semi circular texture 1
- semi circular texture 2 (should be same as texture 1).
- semi circular masking texture (Should be of different color).
- background image (should be same as masking texture ).
- Camera settings :
- camera should be orthographic
- local z position = -10 units.
- Rotation = Zero in all axis
- Import all these textures in unity asset folder.
- Apply each one of them on separate game objects of "Sprite" type .
- Adjust the pivot points of texture 2 and masking texture for proper rotation.
- Adjust the textures in proper layers by setting the "z" value of their transform's local position in the inspector window .
- Background should be kept in the last layer.
- Texture 1 and 2 in same layer.
- Masking texture should be kept in the layer above texture 1 and 2.
The masking texture is rotated along its pivot in the xy plane with an rotationAngle , where,
rotationAngle = 360 / Time (sec) .
As soon as the masking texture has rotated 180 degrees , the mask rotation is stopped and the masking texture is sent back of the background texture , thereby making it invisible ( you can also make it 's renderer off to get same result ) .Simultaneously , texture 2 is set to rotation for another 180 degrees .
And finally , what you see is a clocked timer .
The unity package consists of timer prefab , ProgressManager script (in C #) and dummy textures .
The script has bool variable named " StartTimer " . Check to start the timer .
The needed files and complete Unity package can be downloaded from HERE .
Note : This is just a small hack for those who don't want to get into the intense and complex unity shaders and masking for their 2D games .Using this , one can also make semi - circular progress bar ( use your wits and you can achieve this too) .
Nice tutorial:)
ReplyDelete