Unity Quick Tip - Using Calculations to set Values

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.

Creating a new 3D project

We’ll then add a cube by clicking the plus button on the Hierarchy panel and selecting 3D Object->Cube.

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

Setting the scale 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

Setting scale to two divide by seven

and it will work it out for us.

Calculated scale

It also supports much more complex equations. For example, we could type the following

Setting scale to five multiplied by four over three plus one

and it would calculate the value.

Calculated scale

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

Setting the red channel to 255 divided by 2

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.

Thanks.

Comments

Popular posts from this blog

Rotating a Character in the Direction of Movement - Unity Game Development Tutorial

Creating Terrain from Heightmaps - Unity Game Development Tutorial

Simple Movement using Gamepad and Keyboard - Unity Game Development Tutorial