1 using UnityEngine;
2 using
System.Collections;
3 using
UnityEngine.SceneManagement;
4 using
UnityEngine.EventSystems;
5 using
System.Collections.Generic;
6
7 public
class MainMenuScript : MonoBehaviour
8 {
9     
// Use this for initialization
10     
void Start()
11     {
12
13     }
14
15     
// Update is called once per frame
16     
void Update()
17     {
18
19         
//Click or Tap on Cat to goto CatRunGameScene
20         
if (Input.GetMouseButtonDown(0))
21         {
22             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
23             RaycastHit hit;
24             
if (Physics.Raycast(ray, out hit))
25             {
26                 
if (!IsPointerOverUIObject())
27                 {
28                     
//Select Stage
29                     
if (hit.transform.name == "KittenMain")
30                     {
31                         SceneManager.LoadScene(
"CatRunGame");
32                     }
33                 }
34             }
35         }
36
37         
//Exit Application
38         exitApplication();
39
40     }
41
42     
//Exit Application
43     
void exitApplication()
44     {
45         
if (Input.GetKeyUp(KeyCode.Escape))
46         {
47             Application.Quit();
48         }
49     }
50
51     
//When Touching UI
52     
private bool IsPointerOverUIObject()
53     {
54         PointerEventData eventDataCurrentPosition =
new PointerEventData(EventSystem.current);
55         eventDataCurrentPosition.position =
new Vector2(Input.mousePosition.x, Input.mousePosition.y);
56         List<RaycastResult> results =
new List<RaycastResult>();
57         EventSystem.current.RaycastAll(eventDataCurrentPosition, results);
58         
return results.Count > 0;
59     }
60
61 }


Use this for initialization

Update is called once per frame

Click or Tap on Cat to goto CatRunGameScene

Select Stage

Exit Application

Exit Application

When Touching UI



Gõ tìm kiếm nhanh...