GUI SKIN Menu
Membuat Gui Sceen Menu / Menu Utama
+Buatlah Sceen Baru dengan gameobject dan GUITextture untuk backgroundya....
Klik CreateEmpty->GameObject->Add Component->GUITextture
atur
Transform position : 0.5 - 0.5 - 0
dan arahkan texture ke background image yang diinginkan...
Buat GUISceen melalui klik kanan Assets ->Create ->GUI Sceen
Beri nama GUISceen misalkan SkinUtama
Buat code sbb:
dan masukkan ke GameObject-> lalu pada mySkin masukkan : SkinUtama
using UnityEngine;
using System.Collections;
public class MenuSkin : MonoBehaviour {
public GUISkin mySkin;
bool value = true;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI () {
GUI.skin = mySkin;
value = GUI.Toggle(new Rect(20, 20, 60,60), value, "");
if (GUI.Button(new Rect(20, Screen.height-70, 200,60), "Mulai")){
Debug.Log("Mulai diklik!");
}
if (GUI.Button(new Rect(240, Screen.height-70, 200,60),"Pilihan")){
Debug.Log("Pilihan diklik!");
}
if (GUI.Button(new Rect(460, Screen.height-70, 200,60),"Keluar")){
Application.Quit();
}
}
}
Agar lebih menarik atur font juga properties normal dan hover button dan toggle
Untuk pengaturan suara/ musik latar belakang:
Masukkan GameObject-> Audio ->Audio Source
Masukkan pada Audio Clip : mp3/ogg/wav lagu yang hendak di jalankan.
Play On Awaka adalah : pilihan lagu langsung autostart saat aplikasi dijalankan....
Masukkan code sbb pada gameObject Audio:
using UnityEngine;
using System.Collections;
public class AudioOption : MonoBehaviour {
AudioSource myAudio;
string btn;
float vol = 1, pit = 1;
// Use this for initialization
void Start () {
myAudio = GetComponent<AudioSource>();
btn = "Stop";
vol = PlayerPrefs.GetFloat("paramSuara");
pit = PlayerPrefs.GetFloat("paramNada");
}
// Update is called once per frame
void Update () {
}
void OnGUI () {
GUILayout.BeginArea(new Rect(10,10,200,200));
vol = GUILayout.HorizontalSlider(vol, 0, 1);
pit = GUILayout.HorizontalSlider(pit, 0, 1);
myAudio.volume = vol;
myAudio.pitch = pit;
if (GUILayout.Button(btn)){
if (btn == "Stop"){
myAudio.Stop();
btn = "Play";
} else {
myAudio.Play();
btn = "Stop";
}
}
if (GUILayout.Button("Simpan")){
PlayerPrefs.SetFloat("paramSuara",vol);
PlayerPrefs.SetFloat("paramNada",pit);
}
GUILayout.EndArea();
}
}
+Buatlah Sceen Baru dengan gameobject dan GUITextture untuk backgroundya....
Klik CreateEmpty->GameObject->Add Component->GUITextture
atur
Transform position : 0.5 - 0.5 - 0
dan arahkan texture ke background image yang diinginkan...
Buat GUISceen melalui klik kanan Assets ->Create ->GUI Sceen
Beri nama GUISceen misalkan SkinUtama
Buat code sbb:
dan masukkan ke GameObject-> lalu pada mySkin masukkan : SkinUtama
using UnityEngine;
using System.Collections;
public class MenuSkin : MonoBehaviour {
public GUISkin mySkin;
bool value = true;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI () {
GUI.skin = mySkin;
value = GUI.Toggle(new Rect(20, 20, 60,60), value, "");
if (GUI.Button(new Rect(20, Screen.height-70, 200,60), "Mulai")){
Debug.Log("Mulai diklik!");
}
if (GUI.Button(new Rect(240, Screen.height-70, 200,60),"Pilihan")){
Debug.Log("Pilihan diklik!");
}
if (GUI.Button(new Rect(460, Screen.height-70, 200,60),"Keluar")){
Application.Quit();
}
}
}
Agar lebih menarik atur font juga properties normal dan hover button dan toggle
Untuk pengaturan suara/ musik latar belakang:
Masukkan GameObject-> Audio ->Audio Source
Masukkan pada Audio Clip : mp3/ogg/wav lagu yang hendak di jalankan.
Play On Awaka adalah : pilihan lagu langsung autostart saat aplikasi dijalankan....
Masukkan code sbb pada gameObject Audio:
using UnityEngine;
using System.Collections;
public class AudioOption : MonoBehaviour {
AudioSource myAudio;
string btn;
float vol = 1, pit = 1;
// Use this for initialization
void Start () {
myAudio = GetComponent<AudioSource>();
btn = "Stop";
vol = PlayerPrefs.GetFloat("paramSuara");
pit = PlayerPrefs.GetFloat("paramNada");
}
// Update is called once per frame
void Update () {
}
void OnGUI () {
GUILayout.BeginArea(new Rect(10,10,200,200));
vol = GUILayout.HorizontalSlider(vol, 0, 1);
pit = GUILayout.HorizontalSlider(pit, 0, 1);
myAudio.volume = vol;
myAudio.pitch = pit;
if (GUILayout.Button(btn)){
if (btn == "Stop"){
myAudio.Stop();
btn = "Play";
} else {
myAudio.Play();
btn = "Stop";
}
}
if (GUILayout.Button("Simpan")){
PlayerPrefs.SetFloat("paramSuara",vol);
PlayerPrefs.SetFloat("paramNada",pit);
}
GUILayout.EndArea();
}
}
Hasil pengaturan akan di rekam pada sistem :
perekaman di PlayerPrefs
HKCU/Software/<Company Name>/<Product Name>
GUI SKIN Menu
Reviewed by ADIARRAY
on
19.29
Rating:
Tidak ada komentar: