Conditional digunakan untuk mengetes suatu kondisi dimana hasilnya akan mengembalikan suatu nilai yang nantinya dapat kita olah sesuai dengan kebutuhan program kita buat. Dalam proses pembuatan logik game kondisional sangat berperan penting juga.
Sebagai contoh :
using UnityEngine;
using System.Collections;
public class Conditional : MonoBehaviour {
public float speed;
public float maxSpeed;
// Use this for initialization
void Start () {
speed = 3.0f;
maxSpeed = 5.0f;
}
// Update is called once per frame
void Update () {
if (speed < maxSpeed) {
Debug.Log ("Max Speed more faster than Speed");
} else {
Debug.Log ("Max Speed is lower than Speed ");
}
}
}
Hasil dari console adalah : Max Speed more faster than Speed
Ini disebabkan nilai return dari kondisi if (speed < maxSpeed) adalah true atau benar maka console akan menulis sesuai dengan kondisi yang tadi kita tes.
Sebagai contoh :
using UnityEngine;
using System.Collections;
public class Conditional : MonoBehaviour {
public float speed;
public float maxSpeed;
// Use this for initialization
void Start () {
speed = 3.0f;
maxSpeed = 5.0f;
}
// Update is called once per frame
void Update () {
if (speed < maxSpeed) {
Debug.Log ("Max Speed more faster than Speed");
} else {
Debug.Log ("Max Speed is lower than Speed ");
}
}
}
Hasil dari console adalah : Max Speed more faster than Speed
Ini disebabkan nilai return dari kondisi if (speed < maxSpeed) adalah true atau benar maka console akan menulis sesuai dengan kondisi yang tadi kita tes.
Post A Comment:
0 comments: