Ejemplo n.º 1
0
    private void OnTriggerStay(Collider other)
    {
//        Debug.Log($"In Trigger: {other}");

        PlayerAgent playerAgent = other.gameObject.GetComponentInParent <PlayerAgent>();

        if (playerAgent != null)
        {
            playerAgent.OnPlayerTriggerStay(this.GetComponent <Collider>(), other);

            if (controller.IsAttacking)
            {
                if (!attackStarted)
                {
                    attackStartTime = Time.time;
                    damageApplied   = 0;

                    attackStarted = true;
                }

                int damageExpected = (int)((Time.time - attackStartTime) * (float)controller.player.DamageAmount) + 1;
                if (damageExpected != damageApplied)
                {
                    playerAgent.DoDamage(damageExpected - damageApplied);

                    damageApplied = damageExpected;
                }
            }
            else
            {
                attackStartTime = 0.0f;
                damageApplied   = 0;
                attackStarted   = false;
            }
        }
    }