9. DİL SEÇİMİ
C# Javascript
Tercihim C#:
• Daha kati (strict typing) bir dil olmasi
• IDE acisindan avantajli olmasi (Visual Studio rules)
• Unity API’sinin naming convention seciminin bu yonde
olmasi. (Büyük harfle başlayan method isimleri)
• Event sisteminde kolaylık sağlaması
10. Accessing Components
• Unity’de oyunumuzda kullandigimiz butun objeler
GameObject’den extend ediyor.
• Bir objenin kamera / kup / collider / light olduguna
eklenen component’lar karar veriyor.
• Objelerimize ekledigimiz component’larin hepsi aslinda
birer script blogu (vice versa)
11. Accessing Components (cont...)
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
void Example() {
GetComponent<SomeScript>().doSomething();
}
}
12. Accessing Objects
• Inspector’a referans verilebilir
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public Transform target;
void Update() {
target.Translate(0, 1, 0);
}
}
13. Accessing Objects (cont...)
• Ayni hiyerarsi icinde bulunan yani kendisine parent veya
child olan objelere transform.Find() methodu ile ulasarak
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
void Example() {
transform.Find("Hand").Translate(0, 1, 0);
}
}
14. Accessing Objects (cont...)
• ve FindObjectsOfType ile bir tipteki bütün
FindObjectOfType
scriptlere/componentlara ulaşılabilir.
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
void Start() {
OtherScript other = FindObjectOfType(typeof(OtherScript));
other.DoSomething();
}
}
15. Accessing Objects (cont...)
• GameObject.Find()ve GameObject.FindWithTag() ile isim ve
etikete gore arama yapilabilir.
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
void Start() {
GameObject go = GameObject.Find("Haydar");
go.transform.Translate(0, 1, 0);
GameObject player = GameObject.FindWithTag("Player");
player.transform.Translate(0, 1, 0);
}
}
16. Accessing Objects (cont...)
• Buradan yola çıkarak objelere bağlı scriptlere ulaşılabilir
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
void Start() {
GameObject go = GameObject.Find("Murtaza");
go.GetComponent<OtherScript>().DoSomething();
GameObject player = GameObject.FindWithTag("Player");
player.GetComponent<OtherScript>().DoSomething();
}
}
18. Instantiating
• Instantiate methodu, instantiate edilecek obje, rotasyon
ve pozisyon verisiyle birlikte cagirilir.
Transform clonedObject = Instantiate(testObject,transform.position,transform.rotation)
Destroy
• GameObject, component veya bir asset’i kaldirmak icin
kullanilir
Destroy(gameObject);
Destroy();
Destroy(rigidbody);
Destroy(gameObject, 5);
19. Platform Spesific Features
• Bu tip ozellikleri gorebilecegimiz yer MonoBehaviour
class’i
Awake
Update
LateUpdate
FixedUpdate
Start
OnTriggerEnter
OnCollisionEnter