Skip to Content
Unity 2017 Mobile Game Development
book

Unity 2017 Mobile Game Development

by John P. Doran
November 2017
Beginner to intermediate content levelBeginner to intermediate
360 pages
6h 40m
English
Packt Publishing
Content preview from Unity 2017 Mobile Game Development

The Range attribute

Another thing that we can use to protect our code is the Range attribute. This will allow us to specify a minimum and maximum value for a variable. Since we want the player to always be moving forward, we may want to restrict the player from moving backward. To do that, we can add the following highlighted line of code:

    [Tooltip("How fast the ball moves forwards automatically")]     [Range(0, 10)]     public float rollSpeed = 5; 

Save your script, and return to the editor:

We have now added a slider beside our value, and we can drag it to adjust between our minimum and maximum values. Not only does this protect our variable, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Holistic Mobile Game Development with Unity

Holistic Mobile Game Development with Unity

Penny de Byl
Hands-On Unity 2020 Game Development

Hands-On Unity 2020 Game Development

Nicolas Alejandro Borromeo

Publisher Resources

ISBN: 9781787288713Supplemental Content