Beispiel #1
0
    // Aqui moveremos y giraremos la araña en funcion del Input
    void FixedUpdate()
    {
        // Si estoy en pausa no hacer nada (no moverme ni atacar)
        if (paused)
        {
            return;
        }

        /////////////////////////////////////////////////////////////////////////////////////
        // Si giro izquierda: _angularSpeed = -rotateSpeed;
        // Calculo de velocidad lineal (_speed) y angular (_angularSpeed) en función del Input
        // Si camino/corro hacia delante delante: _speed = walkSpeed   /  _speed = runSpeed
        // Si camino / corro hacia delante detras: _speed = -walkSpeed / _speed = -runSpeed
        // Si no me muevo: _speed = 0
        /////////////////////////////////////////////////////////////////////////////////////

        /////////////////////////////////////////////////////////////////////////////////////
        // Si giro izquierda: _angularSpeed = -rotateSpeed;
        // Si giro izquierda: _angularSpeed = -rotateSpeed;
        // Si giro derecha: _angularSpeed = rotateSpeed;
        // Si no giro : _angularSpeed = 0;
        /////////////////////////////////////////////////////////////////////////////////////
#if UNITY_IOS || UNITY_ANDROID
        float direction = 0f;
        if (CrossButton.GetInput(InputType.UP))
        {
            direction = 1f;
        }
        else if (CrossButton.GetInput(InputType.DOWN))
        {
            direction = -1f;
        }

        if (RunButton.IsRun())
        {
            _speed = direction * runSpeed;
        }
        else
        {
            _speed = direction * walkSpeed;
        }

        float torqueDirection = 0f;
        if (CrossButton.GetInput(InputType.RIGHT))
        {
            torqueDirection = 1f;
        }
        else if (CrossButton.GetInput(InputType.LEFT))
        {
            torqueDirection = -1f;
        }
        _angularSpeed = torqueDirection * rotateSpeed;
#else
        float verticalAxis = Input.GetAxis("Vertical");
        if (Input.GetButton("Run"))
        {
            _speed = verticalAxis * runSpeed;
        }
        else
        {
            _speed = verticalAxis * walkSpeed;
        }


        _angularSpeed = Input.GetAxis("Horizontal") * rotateSpeed;
#endif

        // Actualizamos el parámetro "Speed" en función de _speed. Para activar la anicación de caminar/correr
        _animator.SetFloat(SpeedHash, _speed);

        // Movemov y rotamos el rigidbody (MovePosition y MoveRotation) en función de "_speed" y "_angularSpeed"
        _rigidbody.MovePosition(transform.position + transform.forward * _speed * Time.deltaTime);
        _rigidbody.MoveRotation(transform.rotation * Quaternion.Euler(0, _angularSpeed * Time.deltaTime, 0));

        // Mover el collider en función del parámetro "Distance" (necesario cuando atacamos)
        Vector3 center = _boxCollider.center;
        center.z            = _originalColliderZ + _animator.GetFloat(DistanceHash) * _boxCollider.size.z;
        _boxCollider.center = center;
    }
Beispiel #2
0
    // Aqui moveremos y giraremos la araña en funcion del Input
    void FixedUpdate()
    {
        // Si estoy en pausa no hacer nada (no moverme ni atacar)
        if (paused)
        {
            return;
        }

        // Calculo de velocidad lineal (_speed) y angular (_angularSpeed) en función del Input
        // Si camino/corro hacia delante delante: _speed = walkSpeed   /  _speed = runSpeed
        if (Input.GetKey(KeyCode.UpArrow) || CrossButton.GetInput(InputType.UP))
        {
            if (Input.GetKey(KeyCode.LeftShift) || isPressingRunningButton)
            {
                _speed = runSpeed;
            }
            else
            {
                _speed = walkSpeed;
            }
        }
        // Si camino/corro hacia delante detras: _speed = -walkSpeed   /  _speed = -runSpeed
        else if (Input.GetKey(KeyCode.DownArrow) || CrossButton.GetInput(InputType.DOWN))
        {
            if (Input.GetKey(KeyCode.LeftShift) || isPressingRunningButton)
            {
                _speed = -runSpeed;
            }
            else
            {
                _speed = -walkSpeed;
            }
        }
        else
        {
            // Si no me muevo: _speed = 0
            _speed = 0;
        }



        // Si giro izquierda: _angularSpeed = -rotateSpeed;
        if (Input.GetKey(KeyCode.LeftArrow) || CrossButton.GetInput(InputType.LEFT))
        {
            _angularSpeed = -rotateSpeed;
        }
        // Si giro derecha: _angularSpeed = rotateSpeed;
        else if (Input.GetKey(KeyCode.RightArrow) || CrossButton.GetInput(InputType.RIGHT))
        {
            _angularSpeed = rotateSpeed;
        }
        // Si no giro : _angularSpeed = 0;
        else
        {
            _angularSpeed = 0;
        }

        // Actualizamos el parámetro "Speed" en función de _speed. Para activar la anicación de caminar/correr
        animator.SetFloat("Speed", _speed);

        // Movemov y rotamos el rigidbody (MovePosition y MoveRotation) en función de "_speed" y "_angularSpeed"
        rigidBody.MovePosition(transform.position + (transform.forward * _speed * Time.deltaTime));
        rigidBody.MoveRotation(rigidBody.rotation * Quaternion.Euler(0f, _angularSpeed * Time.deltaTime, 0f));

        // Mover el collider en función del parámetro "Distance" (necesario cuando atacamos)
        box.center = new Vector3(box.center.x, box.center.y, animator.GetFloat("Distance") * _originalColliderZ * 20);
    }
Beispiel #3
0
    // En este bucle solamente comprobaremos si el Input nos indica "atacar" y activaremos el trigger "Attack"
    private void Update()
    {
        // Si estoy en pausa no hacer nada (no moverme ni atacar)
        // TODO
        if (paused)
        {
            return;
        }

        // movimiento por teclado
        _h = Input.GetAxis("Horizontal");
        _v = Input.GetAxis("Vertical");

        // movimiento con crossbutton (a lo cutre)
        if (CrossButton.GetInput(InputType.UP) ||
            (UIButton.GetInput(ButtonType.RUN)))
        {
            _v = 1;                                                     // AUTORUN push button
        }
        if (CrossButton.GetInput(InputType.DOWN))
        {
            _v = -1;
        }
        if (CrossButton.GetInput(InputType.RIGHT))
        {
            _h = 1;
        }
        if (CrossButton.GetInput(InputType.LEFT))
        {
            _h = -1;
        }

        if (CrossButton.GetInput(InputType.UP_LEFT))
        {
            _v = 1; _h = -1;
        }
        if (CrossButton.GetInput(InputType.UP_RIGHT))
        {
            _v = 1; _h = 1;
        }
        if (CrossButton.GetInput(InputType.DOWN_LEFT))
        {
            _v = -1; _h = -1;
        }
        if (CrossButton.GetInput(InputType.DOWN_RIGHT))
        {
            _v = -1; _h = 1;
        }

        // Si detecto Input tecla/boton ataque ==> Activo disparados 'Attack'
        // UIbutton
        if (Input.GetKeyDown(KeyCode.Space) || UIButton.GetInput(ButtonType.ATTACK))
        {
            if (Time.time >= _nextAttackTime)
            {
                if (_an.GetCurrentAnimatorStateInfo(1).fullPathHash != damageHash)
                {
                    _an.SetTrigger(attackHash);
                    _nextAttackTime = Time.time + 1f / _attackRate;
                }
            }
        }
        if (_an.GetFloat("Distance") > 0.02)
        {
            play(_sourceAttack, FxAttack);
        }
    }