Tutorial ini adalah lanjutan dari tutorial augmented reality Bagian 3 Button Rotasi. Jika kamu belum mengetahui Augmented Reality, kamu bisa mempelajari di tutorial sebelumnya pada link berikut ini: Bagian 1 Augmented Reality
Target yang akan dicapai pada tutorial ini adalah sahabat akan dapat membuat tombol yang fungsinya untuk meng-capture tampilan aplikasi dan langsung tersimpan pada direktori yang sahabat inginkan. Baiklah, langsung saja tonton videonya di bawah ini.
Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
using UnityEngine; using System.Collection; public class ARMenu : MonoBehavior { //Membuat variabel untuk resize layar public GUISkin guiSkin; private float guiRatio; private float sWidth; private Vector3 GUIsF; public GameObject sphere; public float kecepatanRotasi = 50f; bool statusRotasi = false; void Awake(){ sWidth = Screen.width; guiRatio = sWidth/1920; GUIsF = new Vector3(guiRatio,guiRatio,1); } void OnGUI(){ GUI.skin = guiSkin; //letakkan function disini CaptureRotasi(); } void CaptureRotasi(){ //Meletakkan tombol dipojok kanan atas GUI.matrix = Matrix4x4.TRS(new Vector3(Screen.width-258*GUIsF.x,GUIsF.y,0),Quartenion.identity,GUIsF); if (statusRotasi==false){ if(GUI.Button(new Rect(-208,10,238,59),”Rotasi”)){ statusRotasi = true; } }else{ if(GUI.Button(new Rect(-208,10,238,59),”Stop Rotasi”)){ statusRotasi = false; } } if(GUI.Button(new Rect(-458,10,238,59),”Capture”)){ Application.CaptureScreenshot(“C:Hasil Capture/capture.png”) } if(GUI.Button(new Rect(40,10,208,59),“Keluar”){ Application.Quit(); //Keluar dari aplikasi } } void Update(){ if(statusRotasi==true){ sphere.transform.Rotate(Vector3.up, kecepatanRotasi * Time.deltaTime); } } } |