void Update()
    {
        if (disabled)
        {
            if (disabledTexture != null)
            {
                myGUITexture.texture = disabledTexture;
            }
            return;
        }
        if (!Selected)
        {
            if (myGUITexture.GetScreenRect().Contains(Input.mousePosition))
            {
                // Was left mouse button pressed while howevering over us
                if (Input.GetMouseButtonDown(0))
                {
                    // grow the image
                    myGUITexture.texture = pressedTexture;

                    // send the onbutton message
                    scene.OnButtonSelect(name);
                    Selected = true;

                    // don't allow button to be repressed.
                    if (waitTime > 0.0f)
                    {
                        Invoke("Unselect", waitTime);
                    }
                }
            }
        }
    }
Example #2
0
    void Update()
    {
        // set up the proper button aspect
        float   aspect        = Camera.main.aspect;
        Vector3 startingScale = myTransform.localScale;

        startingScale.y        = startingScale.x * aspect;
        myTransform.localScale = startingScale;

        if (!Selected)
        {
            if (myGUITexture.GetScreenRect().Contains(Input.mousePosition))
            {
                // Was left mouse button pressed while howevering over us
                if (Input.GetMouseButtonDown(0))
                {
                    // grow the image
                    myTransform.localScale += hoverVector;

                    // send the onbutton message
                    scene.OnButtonSelect(name);
                    Selected = true;

                    // don't allow button to be repressed.
                    if (waitTime > 0.0f)
                    {
                        Invoke("Unselect", waitTime);
                    }
                }
            }
        }
    }
Example #3
0
    // ----------------------------------------------------------------------------------------
    // Name	:	Update
    // Desc	:	Called each frame to detect whether the mouse is over the button. It does this
    //			by casting a ray into the screen and testing it for intersection with the
    //			object's collider.
    // ----------------------------------------------------------------------------------------
    void Update()
    {
        // If this button has not already been clicked on by the user
        if (!Selected && !scene.ActionSelected)
        {
            // Create a ray from the current mouse position into the screen
            Ray        ray = MainCamera.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            // Does the ray intersect our collider
            if (MyCollider && MyCollider.Raycast(ray, out hit, 1000.0f))
            {
                // Was left mouse button pressed while howevering over us
                if (Input.GetMouseButtonDown(0))
                {
                    // If we have been assigned a selection sound then play it
                    if (SelectSound && !SelectSound.isPlaying)
                    {
                        SelectSound.Play();
                    }

                    // Set the current position to the offset position
                    CurrentPosition = OffsetPosition;

                    // Set the color of its material to red
                    if (myTextMesh)
                    {
                        myTextMesh.color = Color.red;
                    }

                    // call the scene's onbutton action
                    scene.OnButtonSelect(MyGameObject.name);

                    // We have been selected so we don't wish to further process this button
                    Selected = true;

                    if (waitTime > 0.0f)
                    {
                        Invoke("Unselect", waitTime);
                    }
                }
                // If the mouse button isn't down then we are hovering over it
                else
                {
                    // Play the hover sound if present
                    if (HoverSound && !HoverSound.isPlaying)
                    {
                        HoverSound.Play();
                    }
                }
            }
            // The mouse is not hovering over this object so set its material back to yellow
            // and its position to the normal position
            else
            {
                if (myTextMesh)
                {
                    myTextMesh.color = originalColor;
                }
                CurrentPosition = OriginalPosition;
            }
        }

        // Always perform a lerp from the current transform's position to our target position (target position)
        // which means when we adjust CurrentPosition, the test will smoothly move there,
        MyTransform.position = Vector3.Lerp(MyTransform.position, CurrentPosition, Time.deltaTime);
    }
Example #4
0
    void OnGUI()
    {
        Color oldGUIColor = GUI.color;

        // fade the game screen behind the GUI menu
        if (fadeTexture)
        {
            GUI.color = new Color(0, 0, 0, 1.0f - scene.GetScreenFade());
            GUI.DrawTexture(new Rect(-1, -1, Screen.width * 2, Screen.height * 2), fadeTexture);

            GUI.color = oldGUIColor;
        }

        if (scene.showingAd)
        {
            return;
        }

        if (boardManager != null)
        {
            if (boardManager.state != GameState.Paused)
            {
                return;
            }
        }

        if (boardManagerSquare != null)
        {
            if (boardManagerSquare.state != GameState.Paused)
            {
                return;
            }
        }

        if (boardManagerEuropean != null)
        {
            if (boardManagerEuropean.state != GameState.Paused)
            {
                return;
            }
        }

        // Assign the custom GUI Skin used by our game
        if (myGUISkin)
        {
            GUI.skin = myGUISkin;
        }

        oldGUIColor = GUI.color;
        // fade the game screen behind the GUI menu
        if (fadeTexture)
        {
            GUI.color = new Color(0, 0, 0, 0.7f);
            GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), fadeTexture);

            GUI.color = oldGUIColor;
        }

        //Set up scaling matrix so we can work in EASY coordinates
        float rx = Screen.width / 1080.0f;
        float ry = Screen.height / 1920.0f;

        // Backup the current GUI matrix as we are about to change it so we can work
        // in standard coordinates for all resolutions
        Matrix4x4 oldMat = GUI.matrix;

        // Set up the scaling matrix
        GUI.matrix = Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.identity, new Vector3(rx, ry, 1));

        // Create the transparent options box below the header
        GUI.Box(PauseBox_ScreenRect, "Game Paused");

        // Create and react to the Continue button being pressed
        if (GUI.Button(Continue_ScreenRect, "Continue"))
        {
            scene.OnButtonSelect("Continue");
        }
        // Create and react to the Quit button
        if (GUI.Button(Quit_ScreenRect, "Main Menu"))
        {
            scene.OnButtonSelect("Main Menu");
        }
        GUI.enabled = (data.userWantsAchievements == 1);
        // Create and react to the Quit button
        if (GUI.Button(Ach_ScreenRect, "Achievements"))
        {
            scene.OnButtonSelect("Achievements");
        }
        // Create and react to the Quit button
        if (GUI.Button(Leader_ScreenRect, "Leaderboards"))
        {
            scene.OnButtonSelect("Leaders");
        }
        GUI.enabled = true;

//		// Create and react to the Quit button
//		if (GUI.Button( Signout_ScreenRect, "Signout"))
//		{
//			scene.OnButtonSelect("Signout");
//		}

        // Restore the matrix
        GUI.matrix = oldMat;
    }