Move a Cube/Circle

In this tutorial we will translate/move a Cube & Circle in Unity's Unlit Shader.


[IMPORTANT]
If you are visiting this website for the very first time, please have a look at the first tutorial, it would help you to understand this tutorial better. Click Here!

Project Setup

First add a plane then rotate it's face toward camera, or set the plane rotation to (90, 180, 0).
Add a unlit shader and apply it to a material, and apply that material to the plane.

open the Unlit Shader in Visual Studio.

Bootstrap Themes



With this rotation of plane, the origin of i.uv is bottom left corner.

Bootstrap Themes

We will start from this point, with UV's origin shifted at the center.
If you don't know how to shift the origin to center, you could follow this tutorial for understanding.
Click Here !

Bootstrap Themes
Bootstrap Themes

UV.x have range of values (-0.5 . . . -0.25 . . . 0.0 . . . 0.25 . . . 0.5) from left to right.
UV.y have range of values (-0.5 . . . -0.25 . . . 0.0 . . . 0.25 . . . 0.5) from bottom to top.
see left image below

Draw a cube on top right side, as highlighted with green cell in the code.

Bootstrap Themes
Bootstrap Themes
Bootstrap Themes

Add 0.2 in x-component of UV. e.g UV.x += 0.2;
It will shift all the UV vectors to left.

For example, if we Add 0.2 in -0.5, it will become -0.3.
if we Add 0.2 in -0.2, it will become 0.0.
if we Add 0.2 in 0.5, it will become 0.7.

Bootstrap Themes
Bootstrap Themes
Bootstrap Themes

[NOTE] _Time.y is same as Time.time in C# Unity.

Add (_Time.y * 0.3) in x-component of UV. highlighted with green cell
It will move the UV vectors to left.

Bootstrap Themes

Similarly if we Add (_Time.y * 0.3) in y-component of UV. highlighted with green cell
It will move the UV vectors to bottom.

Bootstrap Themes

Move The Circle

Write the code highlighted with green cell in your shader.

Bootstrap Themes

Move The Cube/Circle From Inspector

Write the code highlighted with green cell in your shader.

Bootstrap Themes