Project
Beginner Gameplay Scripting
IF Statements
Tutorial
Beginner
5 Mins
Unity Technologies
Overview
You have completed 0% of this Tutorial.
1.
Summary
How to use IF statements to set conditions in your code.
Language
English
Recommended Unity Versions
4
1.
Insert Step Title

using UnityEngine; using System.Collections; public class IfStatements : MonoBehaviour { float coffeeTemperature = 85.0f; float hotLimitTemperature = 70.0f; float coldLimitTemperature = 40.0f; void Update () { if(Input.GetKeyDown(KeyCode.Space)) TemperatureTest(); coffeeTemperature -= Time.deltaTime * 5f; } void TemperatureTest () { // If the coffee's temperature is greater than the hottest drinking temperature... if(coffeeTemperature > hotLimitTemperature) { // ... do this. print("Coffee is too hot."); } // If it isn't, but the coffee temperature is less than the coldest drinking temperature... else if(coffeeTemperature < coldLimitTemperature) { // ... do this. print("Coffee is too cold."); } // If it is neither of those then... else { // ... do this. print("Coffee is just right."); } } }

Woohoo! You nailed this tutorial.
Continue rocking your Beginner Gameplay Scripting project.
Next Step:
Loops
Tutorial
Beginner
5 Mins
Unity Technologies