예제 #1
0
    void ClickAndDestroy()
    {
        if (Input.GetMouseButtonDown(0))
        {
            ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit, 1000f) && Input.GetMouseButtonDown(0) && hit.collider.tag == "Obstacle")
            {
                Destroy(hit.collider.gameObject);
            }
            else if (Physics.Raycast(ray, out hit, 1000f) && Input.GetMouseButtonDown(0) && hit.collider.tag == "ButtonLevel")
            {
                string click;
                int    textLength;
                string selectedLevel;
                string worldName;
                //string thisSceneName;

                worldName = GameManager.Instance.worldName;

                click         = hit.collider.gameObject.name;
                textLength    = click.Length;
                selectedLevel = click.Substring(5, textLength - 5);

                //Scene thisScene = SceneManager.GetActiveScene();
                //thisSceneName = thisScene.name;
                //textLength = thisSceneName.Length;
                //worldName = thisSceneName.Substring(11, 6);
                GameManager.Instance.levelName = selectedLevel;
                SceneManager.LoadScene(worldName + selectedLevel);
                //Debug.Log("selected" + selectedLevel);
                //Debug.Log("world name" +worldName);
                Debug.Log(worldName + selectedLevel);
                DestroyButton();
            }
            else if (Physics.Raycast(ray, out hit, 1000f) && Input.GetMouseButtonDown(0) && hit.collider.tag == "SelectLevel")
            {
                call.GotoSelectLevel();
                Destroy(hit.collider.gameObject);
            }
            else if (Physics.Raycast(ray, out hit, 1000f) && Input.GetMouseButtonDown(0) && hit.collider.tag == "ExitGame")
            {
                call.ExitGame();
                Destroy(hit.collider.gameObject);
            }
            else if (Physics.Raycast(ray, out hit, 1000f) && Input.GetMouseButtonDown(0) && hit.collider.tag == "SecretLevel")
            {
                SceneManager.LoadScene("LevelSecret");
                Destroy(hit.collider.gameObject);
                DestroyButton();
            }
        }
    }