示例#1
0
    // UI RAYCASTING
    public void RayCasting()
    {
        Ray        rayOrigin = new Ray(AimObject.transform.position, AimObject.transform.forward);
        RaycastHit hitInfo;

        Debug.Log("Firing");

        // how to use layer masks: http://answers.unity3d.com/questions/8715/how-do-i-use-layermasks.html
        int layerMask = 1 << 5;         // UI is the 5th layer

        if (Physics.Raycast(rayOrigin, out hitInfo, 100, layerMask))
        {
            Debug.Log("Hit Something");
            Debug.DrawRay(transform.position, transform.forward, Color.green, 1);

            ColourChange ColourScript = hitInfo.collider.gameObject.GetComponentInChildren <ColourChange>();
            ColourScript.Activate();

            if (hitInfo.collider.CompareTag("UIStart"))
            {
                StartButton += 1;
                if (StartButton >= 5)
                {
                    UIScript.UIStart();
                    StartButton = 0;
                }
            }

            if (hitInfo.collider.CompareTag("UICredits"))
            {
                CreditButton += 1;
                if (CreditButton >= 5)
                {
                    UIScript.UICredits();
                    CreditButton = 0;
                }
            }

            if (hitInfo.collider.CompareTag("UICreditsBack"))
            {
                CreditBackButton += 1;
                if (CreditBackButton >= 5)
                {
                    UIScript.UICreditsBack();
                    CreditBackButton = 0;
                }
            }

            if (hitInfo.collider.CompareTag("UIQuit"))
            {
                QuitButton += 1;
                if (QuitButton >= 5)
                {
                    UIScript.UIQuit();
                    Debug.Log("QUITING");
                    QuitButton = 0;
                }
            }

            if (hitInfo.collider.CompareTag("UIGameOn"))
            {
                GameOnButton += 1;
                if (GameOnButton >= 5)
                {
                    UIScript.UIHowTo();
                    GameOnButton = 0;
                }
            }

            if (hitInfo.collider.CompareTag("UIMainMenu"))
            {
                UIMainMenu += 1;
                if (UIMainMenu >= 5)
                {
                    UIMainMenu = 0;

                    // reset statics before game is loaded
                    GameManager.GameStarted = false;
                    gridMakerScript.InitializationStarted = false;

                    Application.LoadLevel(Application.loadedLevel);
                }
            }

            ResetOthers(hitInfo.collider.tag);

            if (hitInfo.collider.CompareTag("Alphabet"))
            {
                hitInfo.collider.gameObject.GetComponent <AlphaUI>().IncrementCounter();
            }
        }
    }