Using the Lerp() function to animate an object
We were using the Lerp()
method previously, but it is important to know that we can use it in two different ways. This recipe covers both of these uses.
Getting ready
We are going to create this recipe from scratch and we don't need any special assets. You can download the example project and go to the Chapter 10 Miscellaneous\Recipe 02 Using the Lerp function to animate an object
directory. Open the Example.unity
scene there and play the game. You will see two objects: RedDot
and BlueDot
(both are children of the Canvas
object). The first one uses the standard Lerp()
method and interpolates its position from a minimum to a maximum value in time. The second one uses the Lerp()
method in a different way and continuously follows the mouse pointer.
RedDot interpolates its position between min and max and BlueDot follows the cursor
How to do it...
To use the Lerp()
function for animating objects, follow these steps:
- First we need to create some objects...