Anda di halaman 1dari 24

Mobile Programming 2

Game
Programming

Pelajaran 2

This work is licensed under a Creative


Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 1
Android
4.0 International License
2.0 MonoBehavior

This work is licensed under a Creative


Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 2
Android
4.0 International License
Isi

● MonoBehavior

● Awake

This work is licensed under a Creative


Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 3
Android
4.0 International License
MonoBehavior

This work is licensed under a Creative


Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 4
Android
4.0 International License
Apa yang dimaksud dengan MonoBehavior?

MonoBehaviour adalah class dasar dari setiap script Unity yang dibuat.
Ketika Anda menggunakan C#, MonoBehaviour secara otomatis (default)
akan tercipta.
Berikut ini kotak centang untuk mengaktifkan atau menonaktifkan
MonoBehaviour (script) pada Unity Editor. Letaknya ada pada
tab Inspector.

This work is licensed under a Creative


Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 5
Android
4.0 International License
• Fungsi MonoBehaviour untuk
menonaktifkan script ketika tidak di-
checklist. Jika fungsi-fungsi tersebut
dinonaktifkan maka tidak akan terjadi apa-
apa pada Log Console. Berikut ini fungsi-
fungsi yang akan dibahas pada modul ini:
• Awake() dan Start()
• Update(), FixedUpdate(), dan LateUpdate()

This work is licensed under a Creative


Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 6
Android
4.0 International License
Awake
Awake digunakan untuk menginisialisasi variabel pada saat
status game belum dimulai.
Awake dipanggil ketika script sedang dijalankan dan setelah
semua objek diinisialisasi Sehingga, Anda dapat memanggil
objek lain.

This work is licensed under a Creative


Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 7
Android
4.0 International License
Contoh kode dari fungsi Awake:

This work is licensed under a Creative


Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 8
Android
4.0 International License
Start
Start dipanggil ketika script diaktifkan tepat sebelum fungsi
Update dipanggil pertama kali.
Seperti fungsi Awake, Start dipanggil tepat saat script dalam
keadaan aktif.
Namun, Awake dipanggil ketika objek script di inisialisasi,
terlepas dari apakah script diaktifkan atau tidak.

This work is licensed under a Creative


Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 9
Android
4.0 International License
Contoh kode dari fungsi Start

This work is licensed under a Creative


Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 10
Android
4.0 International License
Update
Update akan aktif jika MonoBehaviour diaktifkan. Update akan terpanggil
sesudah Start dipanggil. Update adalah fungsi yang paling sering
digunakan untuk menerapkan script game.
Namun, tidak semua MonoBehaviour membutuhkan script Update.
Biasanya kita membuat method baru untuk mendeklarasikan sebuah
fungsi.

This work is licensed under a Creative


Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 11
Android
4.0 International License
Contoh kode dari fungsi update

This work is licensed under a Creative


Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 12
Android
4.0 International License
FixedUpdate
FixedUpdate biasanya digunakan sebagai gantinya Update
ketika bertemu dengan Rigidbody.
Misalnya saat menambahkan physic ke benda.

This work is licensed under a Creative


Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 13
Android
4.0 International License
Contoh kode dari fungsi FixedUpdate

This work is licensed under a Creative


Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 14
Android
4.0 International License
LateUpdate
LateUpdate dipanggil setelah semua fungsi Update dipanggil.
Ia berguna untuk memberi log console eksekusi script.
Contohnya, Camera Follow harus selalu diimplementasikan di
LateUpdate karena melacak objek yang mungkin telah
bergerak di dalam Update.

This work is licensed under a Creative


Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 15
Android
4.0 International License
Contoh kode dari fungsi LateUpdate

This work is licensed under a Creative


Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 16
Android
4.0 International License
Contoh penerapan Update, FixedUpdate dan LateUpdate

This work is licensed under a Creative


Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 17
Android
4.0 International License
Editor Script
Untuk Editor Script, secara default Unity
menggunakan MonoDevelop sebagai Editor Script.
Jika Anda ingin menggunakan Editor yang lebih terdepan,
Anda dapat menggunakan Visual Studio.
Tetapi jika ingin yang lebih ringan, Anda dapat
menggunakan Notepad++ . Pemilihan itu tergantung
kenyamanan Anda dalam menulis kode dan spesifikasi
komputer Anda. This work is licensed under a Creative
Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 18
Android
4.0 International License
Untuk mengganti editor
script, Anda dapat lakukan
langkah-langkah sebagai
berikut:
Klik
Menu Edit > Preferences...

This work is licensed under a Creative


Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 19
Android
4.0 International License
Pada Jendela Unity Preferences,
buka tab External
Tools kemudian pada External
Script Editor. Anda dapat
memilih editor yang Anda
inginkan dan dapat pula
menambahkan Editor baru
dengan Klik Browse.
This work is licensed under a Creative
Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 20
Android
4.0 International License
MonoDevelop

This work is licensed under a Creative


Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 21
Android
4.0 International License
Visual Studio

This work is licensed under a Creative


Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 22
Android
4.0 International License
Notepad ++

This work is licensed under a Creative


Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 23
Android
4.0 International License
SELESAI

This work is licensed under a Creative


Introduction to
Android Developer Fundamentals Commons Attribution-NonCommercial 24
Android 4.0 International License

Anda mungkin juga menyukai