예제 #1
0
    void OnTriggerStay2D(Collider2D col)
    {
        //on ground, attempt to pick up
        if (!held)
        {
            if (cooldown <= 0.0f)
            {
                if (col.tag == "Player")
                {
                    PlayerAttacks player = col.GetComponentInChildren <PlayerAttacks>();

                    if (GetOwner() == null && player.CanAttack() && !player.HasWeapon())
                    {
                        player.SwitchWeapon(transform);
                    }
                }
            }
        }
        //held, so it's an attack
        else if (held && !doneDamage)
        {
            Debug.Log("Trying to attack");
            Debug.Log(col.tag);
            Debug.Log(col.name);
            if (col.gameObject.tag == "Player")
            {
                Debug.Log("Player detected");
                PlayerController player = col.GetComponentInChildren <PlayerController>();

                if (GetOwner().GetComponentInChildren <PlayerController>() != player)
                {
                    player.takeDamage(damage);
                    Debug.Log("aaa");
                    doneDamage = true;
                }
            }
        }
    }