1 using UnityEngine;
2 using System.Collections;
3 using UnityEngine.UI;
4 using UnityEngine.SceneManagement;
5
6 public class RealWorldCamScript : MonoBehaviour
7 {
8
9 public static WebCamTexture backCam;
10 GameObject arCube;
11
12 //AR 3D Options
13 Text txt3D;
14 Text txtAR;
15
16 //None Material
17 public Material noneMaterial;
18 public Material skyMaterial;
19
20 //Envirnment
21 GameObject environment;
22 GameObject environmentAR;
23
24 // Use this for initialization
25 void Start()
26 {
27
28 //Envirnment
29 environment = GameObject.Find("Environment");
30 environmentAR = GameObject.Find("EnvironmentAR");
31
32 //Get AR Cube
33 arCube = GameObject.Find("Camera/ARCamCube");
34
35 //AR 3D Options
36 txt3D = GameObject.Find("Canvas/btn3D").GetComponentInChildren<Text>();
37 txtAR = GameObject.Find("Canvas/btnAR").GetComponentInChildren<Text>();
38
39 //Initial Settings
40 if (PlayerPrefs.GetString("GameMode") == "3D" || PlayerPrefs.GetString("GameMode") == "")
41 {
42 menuButton3D();
43 }
44
45 if (PlayerPrefs.GetString("GameMode") == "AR")
46 {
47 menuButtonAR();
48 }
49 }
50
51 public void menuButton3D()
52 {
53
54 PlayerPrefs.SetString("GameMode", "3D");
55
56 arCube.SetActive(false);
57
58 //AR Cam stop if playing
59 if (backCam != null)
60 {
61 if (backCam.isPlaying)
62 backCam.Stop();
63 }
64
65 //AR 3D Options
66 txt3D.color = Color.green;
67 txtAR.color = Color.white;
68
69 //Set SkyBox
70 RenderSettings.skybox = skyMaterial;
71
72 //Set Environment
73 environment.SetActive(true);
74 environmentAR.SetActive(false);
75
76 //Set GameMode
77 PlayerPrefs.SetString("GameMode", "3D");
78
79 }
80
81 public void menuButtonAR()
82 {
83
84 PlayerPrefs.SetString("GameMode", "AR");
85
86 arCube.SetActive(true);
87
88 float worldScreenHeight = Camera.main.orthographicSize * 12.0f;//12.0f;//17
89 float worldScreenWidth = worldScreenHeight / Screen.height * Screen.width;
90 arCube.transform.localScale = new Vector3(worldScreenWidth, worldScreenHeight, 0.1f);
91
92 //Opacity
93 //GetComponent<MeshRenderer>().material.color = new Color(1.0f, 1.0f, 1.0f, 0.9f);
94
95 if (backCam == null)
96 backCam = new WebCamTexture();
97
98 arCube.GetComponent<Renderer>().material.mainTexture = backCam;
99
100 if (!backCam.isPlaying)
101 backCam.Play();
102
103 //AR 3D Options
104 txt3D.color = Color.white;
105 txtAR.color = Color.green;
106
107 //Set SkyBox
108 RenderSettings.skybox = noneMaterial;
109
110 //Set Environment
111 environment.SetActive(false);
112 environmentAR.SetActive(true);
113
114 //Set GameMode
115 PlayerPrefs.SetString("GameMode", "AR");
116
117 }
118
119 //Back Button On the CatRunGame Scene
120 public void menuBtnBack()
121 {
122 SceneManager.LoadScene("MainScene");
123 }
124
125 // Update is called once per frame
126 void Update()
127 {
128 //If escape press or back button on android
129 if (Input.GetKeyUp(KeyCode.Escape))
130 {
131 SceneManager.LoadScene("MainScene");
132 }
133 }
134
135 }
AR 3D Options
None Material
Envirnment
Use this for initialization
Envirnment
Get AR Cube
AR 3D Options
Initial Settings
AR Cam stop if playing
AR 3D Options
Set SkyBox
Set Environment
Set GameMode
float worldScreenHeight = Camera.main.orthographicSize * 12.0f;12.0f;17
Opacity
GetComponent().material.color = new Color(1.0f, 1.0f, 1.0f, 0.9f);
AR 3D Options
Set SkyBox
Set Environment
Set GameMode
Back Button On the CatRunGame Scene
Update is called once per frame
If escape press or back button on android