示例#1
0
    IEnumerator JumpAttack()
    {
        // Choose target
        target.transform.position = player.position;
        mover.target = target;

        // Calculate trajectory and timing
        mover.speed = moverSpeed;
        var toPlayer = target.transform.position - transform.position;
        var jumpTime = Mathf.Clamp(toPlayer.magnitude * (1f / mover.speed), 1.5f, 3f);

        mover.SetJumpTime(jumpTime);

        // Jump
        mover.Jump();

        while (mover.IsJumping)
        {
            jumpAttacker.Attack();
            yield return(null);
        }

        // Randomly spawn debris
        if (++attackCount % debrisInterval == 0)
        {
            // Send debris somewhere between boss and player
            var debrisPosition = Vector3.Lerp(transform.position, player.position, Random.Range(0.25f, 0.75f));
            var debrisObj      = Instantiate(debrisPrefab, debrisPosition + Vector3.up * 2f, Quaternion.Euler(new Vector3(0f, 0f, Random.Range(0f, 360f)))) as GameObject;
            var debris         = debrisObj.GetComponent <BossDebris>();

            debris.GoalPosition = debrisPosition;
        }

        mover.target = null;

        StartCoroutine(Idle());
    }
示例#2
0
 void OnTriggerEnter2D()
 {
     attacker.Attack();
 }