Unity Quick Tip - Using Calculations to set Values
In this quick tip we're going to look at a really useful feature of Unity, that allows you to input mathematical equations when setting values through the interface.
If you'd prefer to watch the video version of this tutorial please click here.
To demonstrate this, we’ll create a new 3D Project.
We’ll then add a cube by clicking the plus button on the Hierarchy panel and selecting 3D Object->Cube.
Let’s say we wanted to double the scale of this cube along the x axis. We could work it out in our head and just set the value to two.
However, what if we now wanted to make it a seventh of the size. That’s a bit trickier to work out in our head. Fortunately, Unity allows us to enter calculations in these fields, so we can type the following
and it will work it out for us.
It also supports much more complex equations. For example, we could type the following
and it would calculate the value.
This same technique can be used when setting any number values. For another example we’ll now create a material by clicking the plus button on the Project panel and selecting Material.
We can now set the Albedo colour of the material to have half as much red by typing the following
That covers everything for this tip. We hope that you found it useful. Please leave any questions or feedback in the comments below, and don't forget to subscribe to get notified when we publish our next post.
Post a Comment