-1
\$\begingroup\$

I have a powerup that randomly drops from enemies. Right now I have it set up using onTriggerEnter2D and am checking for the player collider tag for the pickup to take effect.

    public class FireRatePowerUpScript : MonoBehaviour
{


    public float incrementRate = 1.3f;
    private Animator anim;

    private Weapon weapon;

    // Use this for initialization
    void Start()
    {
        anim = gameObject.GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {

    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag == "Player")
        {
            weapon = collision.gameObject.GetComponentInChildren<Weapon>();
            weapon.fireRate *= incrementRate;
            anim.SetTrigger("goPoof");
            Destroy(gameObject, 1f);
        }
    }
}

How do I change it so that instead of the player character bumping into it I have the player click or tap on it to activate/register?

Thanks

\$\endgroup\$
2
\$\begingroup\$

Have you tried the OnMouseDown method? It's a message called on MonoBehaviour.

private void OnMouseDown()
{
     weapon = GameObject.FindWithTag("Player").GetComponentInChildren<Weapon>();
     weapon.fireRate *= incrementRate;
     anim.SetTrigger("goPoof");
     Destroy(gameObject, 1f);
}

See the Unity documentation on this method here

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.