AddPoints() public method

public AddPoints ( int itemAdd ) : void
itemAdd int
return void
示例#1
0
    public int itemAdd;     // creates counter that can be passed to player control; add amount in inspector

    void OnTriggerEnter2D(Collider2D other)
    {
        //this "if" statement confirms that only the player will be allowed to pick the object up (this is assuming the player script is called "PlayerControl")
        //this is needed in case monsters who also may ahve the box collider2d component, will not pick up the item
        if (other.GetComponent <PlayerControl>() == null)
        {
            return;
        }

        PlayerControl.AddPoints(itemAdd); // on collison, will add the amount in player script
        Destroy(gameObject);              //destroys the object
    }
示例#2
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;
                }
            }
        }
    }