Inheritance: MonoBehaviour
示例#1
0
    void Update()
    {
        //if player is overlapping item
        if (playerTouching == true)
        {
            float xNegPosition = transform.position.x - clickOffsetX;
            float xPosPosition = transform.position.x + clickOffsetX;
            float yPosPosition = transform.position.y + clickOffsetY;
            float yNegPosition = transform.position.y - clickOffsetY;

            ///get position of click
            clickPosition.x = Camera.main.ScreenToWorldPoint(Input.mousePosition).x;
            clickPosition.y = Camera.main.ScreenToWorldPoint(Input.mousePosition).y;

            if (Input.GetKeyDown(KeyCode.Space) || ((yNegPosition < clickPosition.y && clickPosition.y < yPosPosition) &&
                                                    (xNegPosition < clickPosition.x && clickPosition.x < xPosPosition) && Input.GetMouseButtonDown(0)))
            {
                fadingDarkness = playerScript.fadingDarknessScript;
                if (textActive == true)
                {
                    Time.timeScale = 1;
                    pause.busy     = false;
                    playerScript.AddPoints(itemAdd); //will add the amount in player script
                    Destroy(gameObject);             //destroys the object
                }
                else
                {
                    itemTextPanel.SetActive(true);
                    pause.busy = true;
                    flash      = true;
                    textActive = true;
                    if (dialogueToPlay != null)
                    {
                        audioHandler.PlayVoice(dialogueToPlay);
                    }
                    Time.timeScale = 0;
                }
                if (fadingDarkness == null)
                {
                    Debug.Log("not found");
                }
                else
                {
                    fadingDarkness.flash = true;
                }
            }
        }
    }
    void Update()
    {
        //if player is overlapping item
        if (playerTouching == true)
        {
            float xNegPosition = transform.position.x - clickOffsetX;
            float xPosPosition = transform.position.x + clickOffsetX;
            float yPosPosition = transform.position.y + clickOffsetY;
            float yNegPosition = transform.position.y - clickOffsetY;

            ///get position of click
            clickPosition.x = Camera.main.ScreenToWorldPoint(Input.mousePosition).x;
            clickPosition.y = Camera.main.ScreenToWorldPoint(Input.mousePosition).y;

            if (Input.GetKeyDown(KeyCode.Space) || ((yNegPosition < clickPosition.y && clickPosition.y < yPosPosition) &&
                (xNegPosition < clickPosition.x && clickPosition.x < xPosPosition) && Input.GetMouseButtonDown(0)))
            {

                fadingDarkness = playerScript.fadingDarknessScript;

                    playerScript.AddPoints(itemAdd); //will add the amount in player script
                    Destroy(gameObject); //destroys the object
                    flash = true;
                    if (dialogueToPlay != null)
                    {
                        audioHandler.PlayVoice(dialogueToPlay);
                    }

                }
                if (fadingDarkness == null)
                {
                    //Debug.Log("not found");
                }
                else
                {
                    fadingDarkness.flash = true;
                }

        }
    }