Ejemplo n.º 1
0
    void FixedUpdate()
    {
        Vector3 leftStickInputDir  = _inputDevice.LeftStick;
        Vector3 rightStickInputDir = _inputDevice.RightStick;

        _rigidBody.velocity = leftStickInputDir * _currentMoveSpeed;

        animator.SetBool("isWalk", leftStickInputDir.x != 0 || leftStickInputDir.y != 0);
        animator.SetFloat("moveX", leftStickInputDir.x);
        animator.SetFloat("moveY", leftStickInputDir.y);

        if (_activeMissile == null)
        {
            if (!_bazookaSprite.enabled)
            {
                _bazookaSprite.enabled = true;
            }

            if (rightStickInputDir.magnitude > 0)
            {
                float angle = Mathf.Atan2(rightStickInputDir.y, rightStickInputDir.x) * Mathf.Rad2Deg;
                bazooka.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
            }
        }

        if (_inputDevice.GetControl(InputControlType.RightTrigger) > 0)
        {
            if (_triggerHeld == false)
            {
                if (_activeMissile == null)
                {
                    StartCoroutine(MoveSlow());

                    _activeMissile = Instantiate(GetNextMissilePrefab(), transform.position, Quaternion.FromToRotation(Vector3.up, rightStickInputDir));
                    _activeMissile.GetComponent <Owner>().player = this;
                    _activeMissile.inputDevice = _inputDevice;

                    _activeMissile.gameObject.layer = gameObject.layer;

                    var spriteRenderer        = GetComponent <SpriteRenderer>();
                    var missileSpriteRenderer = _activeMissile.GetComponent <SpriteRenderer>();
                    missileSpriteRenderer.color = spriteRenderer.color;

                    _activeMissile.TankControls = _tankControls;

                    _bazookaSprite.enabled = false;
                }
                else
                {
                    _activeMissile.Boost();
                }

                _triggerHeld = true;
            }
        }
        else
        {
            if (_triggerHeld == true && _activeMissile && _activeMissile.IsBoosting)
            {
                _activeMissile.GetComponent <Exploder>().Explode();
                _activeMissile = null;
            }
            _triggerHeld = false;
        }
    }