示例#1
0
    void Update()
    {
        BossUIController.Instance.SetHealth((int)Lives);
        bool isMoving = false;

        if (_knockback <= 0)
        {
            if (Vector2.Distance(transform.position, _target.position) > 2)
            {
                isMoving = true;
                GetComponent <SpriteRenderer>().flipX = _target.position.x > transform.position.x;
                transform.position = Vector2.MoveTowards(transform.position, _target.position, Speed * Time.deltaTime);
            }
        }
        _knockback -= Time.deltaTime;

        if (_target.position.x >= transform.position.x && !_attackRight || _target.position.x < transform.position.x && _attackRight)
        {
            _attackRight = !_attackRight;
            Melee.GetComponent <CapsuleCollider2D>().gameObject.transform.Rotate(0, 180, 0);
        }


        if (Time.time > _nextFire && !_specialAnim)
        {
            if (!_fireAnim)
            {
                _animator.SetTrigger("Attack");
                _fireAnim = true;
            }

            if (Time.time > _nextFire + 1f)
            {
                _nextFire = Time.time + _fireRate;
                _fireAnim = false;
            }
        }

        if (Time.time > _nextSpecial && !_fireAnim)
        {
            if (!_specialAnim)
            {
                _animator.SetTrigger("Special");
                _specialAnim = true;
                _knockback   = 1f;
            }
            if (Time.time > _nextSpecial + 1f)
            {
                _nextSpecial = Time.time + _specialRate;
                _specialAnim = false;
                Shoot();
                Shoot();
                Shoot();
            }
        }

        if (Lives <= 0)
        {
            Canvas.SetActive(true);
            Time.timeScale = 0f;

            PlayerController.Instance.Health = PlayerController.Instance.Health + 10;
            GameObject.Destroy(this.gameObject);
        }
        _animator.SetBool("Walk", isMoving);
    }