Esempio n. 1
0
    public override void StartAttack()
    {
        if (lastLaunchTime > 0.0f && Time.time < (lastLaunchTime + coolDown))
        {
            // we cannot fire yet, so wait
            return;
        }

        // play the sound effect
        if (soundEffectPlayer != null)
        {
            soundEffectPlayer.PlayBowSound();
        }

        // remember time for cooldown purposes
        lastLaunchTime = Time.time;

        // show the attack animation
        animator.SetBool("Attack", true);

        // spawn a new arrow
        StartCoroutine(DelayedAction(
                           () => {
            // rotate the arrow
            Quaternion rotation = Quaternion.Euler(GetRotation());

            // position the arrow
            Vector3 position = arrowSpawnPosition.position;

            // spawn the arrow
            GameObject arrow              = Instantiate(arrowPrefab, position, rotation);
            ArrowMovement arrowMovement   = arrow.GetComponent <ArrowMovement>();
            arrowMovement.direction       = GetAttackDirection();
            arrowMovement.targetLayerName = targetLayerName;
            arrowMovement.lifetime        = projectileLifetime;
            arrowMovement.rangedDamage    = arrowDamage;
            arrowMovement.attacker        = this;
        },
                           arrowSpawnDelay
                           ));
    }