PlayerControl.AddPoints C# (CSharp) Method

AddPoints() public method

public AddPoints ( int itemAdd ) : void
itemAdd int
return void
    public void AddPoints(int itemAdd)
    {
        itemCounter += itemAdd; //adds amount to current score
        Debug.Log("Score: " + itemCounter); //confirms the player has picked up the object (track amount). this is removeable.
    }

Usage Example

Ejemplo n.º 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
    }
All Usage Examples Of PlayerControl::AddPoints