UNİTY 3D İF ELSE SİSTEMİ
Bu Derste if, elseif, else Komutunun Ne İşe Yarayıp Nerelerde Kullanıldığının Ve Nasıl Sorgulatma Yapıldığının Bir Örneğini Görüceğiz.
SORGULATMA SCRİPT:
C#
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(coffeeTemperature > hotLimitTemperature)
{
print("Coffee is too hot.");
}
else if(coffeeTemperature < coldLimitTemperature)
{
print("Coffee is too cold.");
}
else
{
print("Coffee is just right.");
}
}
}
JS
#pragma strict
private var coffeeTemperature:float = 85.0f;
private var hotLimitTemperature:float = 70.0f;
private var coldLimitTemperature:float = 40.0f;
function Update ()
{
if(Input.GetKeyDown(KeyCode.Space))
TemperatureTest();
coffeeTemperature -= Time.deltaTime * 5f;
}
function TemperatureTest ()
{
if(coffeeTemperature > hotLimitTemperature)
{
print("Coffee is too hot.");
}
else if(coffeeTemperature < coldLimitTemperature)
{
print("Coffee is too cold.");
}
else
{
print("Coffee is just right.");
}
}