// collision detector
    void OnCollisionEnter2D(Collision2D other)
    {
        playercontroller pc = other.gameObject.GetComponent <playercontroller>();

        if (pc != null)
        {
            pc.ChangeHealth(-1);
        }
    }
    void OnTriggerStay2D(Collider2D other)
    {
        playercontroller pc = other.GetComponent <playercontroller>();

        if (pc != null)
        {
            pc.ChangeHealth(-1);
        }
    }
示例#3
0
    /// <summary>
    /// detect collison
    /// </summary>
    /// <param name="collision"></param>
    void OnTriggerEnter2D(Collider2D other)
    {
        playercontroller pc = other.GetComponent <playercontroller>();

        if (pc != null)
        {
            if (pc.MyCurrentHealth < pc.MyMaxHealth)
            {
                pc.ChangeHealth(1);
                Instantiate(collectEffect, transform.position,
                            Quaternion.identity);
                audioManager.instance.AudioPlay(collectClip);
                Destroy(this.gameObject);
            }
        }
    }