Health limit when pick up object

public int hp;
public GameObject particle;

    // Use this for initialization
    void Start()
    {

    }

    // Update is called once per frame
    void OnTriggerEnter(Collider col)
    {
        if (col.gameObject.tag == "Player")
        {
            Instantiate(particle, transform.position, transform.rotation);
            hp++;
                Destroy(gameObject);
        }
    }

How can i get Health limit? For example if i collect health 3 times my health is 3, i want 3 healths to be max.
After picking up more healths than 3 it will not count! how can i do that?

I suggest checking, with an if statement, what the player’s current health is.

if (hp < 3) { // Do stuff }
If the condition hp < 3 is false, that means the variable hp is either 3 or more, in which case you are at max health and the script should not make the particle effects, increment the hp or destroy the health container.

EDIT:

When I read this a bit more carefully, I am confused as to why you are storing the hp of the player in this class. It is clear from the line hp++ that you are not actually changing the health of the player at all. You are changing the local variable hp.

Can you supply the whole script so the context is more clear?

if (hp < hpMax)
{
hp++;
}

where “hpMax” is your maximum (in this case 3).

Thanks for your help i fixed it!