GetAxis() public method

public GetAxis ( string axisName ) : float
axisName string
return float
Ejemplo n.º 1
0
    void Update()
    {
        if (Input.GetAxis("Horizontal") > 0 || hftInput.GetAxis("Horizontal") > 0)
        {
            transform.localScale = new Vector3(Mathf.Abs(transform.localScale.x), transform.localScale.y, transform.localScale.z);
        }
        else if (Input.GetAxis("Horizontal") < 0 || hftInput.GetAxis("Horizontal") < 0)
        {
            transform.localScale = new Vector3(-Mathf.Abs(transform.localScale.x), transform.localScale.y, transform.localScale.z);
        }

        moveDirection = new Vector3(hftInput.GetAxis("Horizontal") + Input.GetAxis("Horizontal"),
                                    -hftInput.GetAxis("Vertical") - Input.GetAxis("Vertical"), 0);
        moveDirection  = transform.TransformDirection(moveDirection);
        moveDirection *= speed;

        controller.Move(moveDirection * Time.deltaTime);

        if (transform.position.x < leftBound)
        {
            transform.position = new Vector3(leftBound, transform.position.y, 2);
        }
        else if (transform.position.x > rightBound)
        {
            transform.position = new Vector3(rightBound, transform.position.y, 2);
        }
        else if (transform.position.y < lowerBound)
        {
            transform.position = new Vector3(transform.position.x, lowerBound, 2);
        }
        else if (transform.position.y > upperBound)
        {
            transform.position = new Vector3(transform.position.x, upperBound, 2);
        }
    }
Ejemplo n.º 2
0
    // custom functions
    void RotatePlayer()
    {
        transform.eulerAngles += new Vector3(0,
                                             0,
            (-moveSpeed * hInput.GetAxis("Horizontal")) * Time.deltaTime);
       // (-moveSpeed * Input.GetAxis("Horizontal")) * Time.deltaTime);

        playerSprite.localEulerAngles = new Vector3(0, 0,
            hInput.GetAxis("Horizontal") * -30);
       // Input.GetAxis("Horizontal") * -30);
    }
    // Update is called once per frame
    void Update()
    {
        if (setInactiveNextFrame)
        {
            gameObject.SetActive(false);
            setInactiveNextFrame = false;
        }

        if (isActive)
        {
            float dx = (Input.GetAxis("Horizontal") + m_hftInput.GetAxis("Horizontal")) * speed * Time.deltaTime;
            float dy = (Input.GetAxis("Vertical") - m_hftInput.GetAxis("Vertical")) * speed * Time.deltaTime;

            GetComponent <Rigidbody2D> ().velocity = new Vector2(dx * speed, dy * speed);
            //GetComponent<Rigidbody2D> ().AddForce (new Vector2 (dx * 10, dy * 10));
            if (Input.GetKey(KeyCode.Space))
            {
                weapon.fire(this);
            }


            var horizontalDirection = m_hftInput.GetAxis("Horizontal2");
            var verticalDirection   = m_hftInput.GetAxis("Vertical2");

            if (horizontalDirection != 0 || verticalDirection != 0)
            {
                var angle =
                    horizontalDirection > 0 && verticalDirection == 0 ?  90
                                        : horizontalDirection < 0 && verticalDirection == 0 ? -90
                                        : horizontalDirection > 0 && verticalDirection < 0 ? 135
                                        : horizontalDirection < 0 && verticalDirection > 0 ? -35
                                        : horizontalDirection > 0 && verticalDirection > 0 ? 45
                                        : horizontalDirection < 0 && verticalDirection < 0 ? -135
                                        : horizontalDirection == 0 && verticalDirection > 0 ? 0
                                        : horizontalDirection == 0 && verticalDirection < 0 ? 180
                                        : 0f;

                transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
                if (weapon.fire(this))
                {
                    m_soundPlayer.PlaySound(weapon.soundName);
                }
            }



            // keep the player in the bounds of the game
            Vector3 pos = Camera.main.WorldToViewportPoint(transform.position);
            pos.x = Mathf.Clamp01(pos.x);
            pos.y = Mathf.Clamp01(pos.y);
            transform.position = Camera.main.ViewportToWorldPoint(pos);
        }
    }
Ejemplo n.º 4
0
    // Update is called once per frame
    void FixedUpdate()
    {
        // Check if the center under us is touching the ground and
        // pass that info to the Animator
        m_grounded = Physics2D.OverlapCircle(groundCheck.position, m_groundRadius, whatIsGround);
        m_animator.SetBool("Ground", m_grounded);

        // Pass our vertical speed to the animator
        m_animator.SetFloat("vSpeed", m_rigidbody2d.velocity.y);

        // Get left/right input (get both phone and local input)
        float move = m_hftInput.GetAxis("Horizontal") + Input.GetAxis("Horizontal");

        // Pass that to the animator
        m_animator.SetFloat("Speed", Mathf.Abs(move));

        // and move us
        m_rigidbody2d.velocity = new Vector2(move * maxSpeed, m_rigidbody2d.velocity.y);
        if (move > 0 && !m_facingRight)
        {
            Flip();
        }
        else if (move < 0 && m_facingRight)
        {
            Flip();
        }

        if (transform.position.y < LevelSettings.settings.bottomOfLevel.position.y)
        {
            MoveToRandomSpawnPoint();
        }
    }
    void Update()
    {
        if (!characterAssigned && !string.Equals(gp.Name, "nope"))            // on laisse le joueur choisir son nom avant de lui assigner un avatar
        {
            characterAssigned = true;
            isJoueurScene     = string.Equals(gp.Name, "jsceneup") || string.Equals(gp.Name, "jscenedown") ||
                                string.Equals(gp.Name, "jsceneleft") || string.Equals(gp.Name, "jsceneright");
            associerCharacter();
        }

        if (characterAssigned && !dejaJoue)
        {
            if (input.GetAxis("Horizontal") > 0)
            {
                if (!isJoueurScene || string.Equals(gp.Name, "jsceneright"))
                {
                    character.moveRight();
                    dejaJoue = true;
                }
            }
            else if (input.GetAxis("Horizontal") < 0)
            {
                if (!isJoueurScene || string.Equals(gp.Name, "jsceneleft"))
                {
                    character.moveLeft();
                    dejaJoue = true;
                }
            }
            else if (input.GetAxis("Vertical") < 0)                  // axe vertical inverse sur le controller
            {
                if (!isJoueurScene || string.Equals(gp.Name, "jsceneup"))
                {
                    character.moveUp();
                    dejaJoue = true;
                }
            }
            else if (input.GetAxis("Vertical") > 0)
            {
                if (!isJoueurScene || string.Equals(gp.Name, "jscenedown"))
                {
                    character.moveDown();
                    dejaJoue = true;
                }
            }
        }
    }
Ejemplo n.º 6
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (GameManager.isGameStarted)
        {
            // Check if the center under us is touching the ground and
            // pass that info to the Animator
            m_grounded = Physics2D.OverlapCircle(groundCheck.position, m_groundRadius, whatIsGround);
            m_animator.SetBool("Ground", true);

            // Pass our vertical speed to the animator
            // m_animator.SetFloat("vSpeed", m_rigidbody2d.velocity.y);

            // Get left/right input (get both phone and local input)
            //float move = m_hftInput.GetAxis("Horizontal") + Input.GetAxis("Horizontal");
            h = m_hftInput.GetAxis("Horizontal") + Input.GetAxis("Horizontal");
            v = -m_hftInput.GetAxis("Vertical") + Input.GetAxis("Vertical");


            // Pass that to the animator
            m_animator.SetFloat("Speed", Mathf.Abs(h));
            m_animator.SetFloat("vSpeed", v);

            // and move us
            // m_rigidbody2d.velocity = new Vector2(move * maxSpeed, m_rigidbody2d.velocity.y);
            movement.Set(h, v, 0f);


            transform.position += movement.normalized * maxSpeed * Time.deltaTime;
            if (h > 0 && !m_facingRight)
            {
                Flip();
            }
            else if (h < 0 && m_facingRight)
            {
                Flip();
            }

            if (transform.position.y < LevelSettings.settings.bottomOfLevel.position.y)
            {
                MoveToRandomSpawnPoint();
            }
        }
    }
    private void ShipMove()
    {
        // Déplacement horizontal
        if (input.GetAxis("Horizontal") < 0)
        {
            scrv.MoveLeft();
        }
        else if (input.GetAxis("Horizontal") > 0)
        {
            scrv.MoveRight();
        }

        float acc = input.gyro.userAcceleration.magnitude;

        if (acc > 20)
        {
            scrv.Shake(acc);
        }
        else
        {
            scrv.StopShake();
        }
    }
Ejemplo n.º 8
0
    void Update()
    {
        if (Input.GetAxis("Horizontal") > 0 || hftInput.GetAxis("Horizontal") > 0)
        {
            //meshFilter.mesh = runFrames[3];
            //nextFrameChange = 0.0f;
            transform.localScale = new Vector3(-Mathf.Abs(transform.localScale.x), transform.localScale.y, transform.localScale.z);
            isStanding           = false;
        }
        else if (Input.GetAxis("Horizontal") < 0 || hftInput.GetAxis("Horizontal") < 0)
        {
            //meshFilter.mesh = runFrames[3];
            //nextFrameChange = 0.0f;
            transform.localScale = new Vector3(Mathf.Abs(transform.localScale.x), transform.localScale.y, transform.localScale.z);
            isStanding           = false;
        }
        else
        {
            isStanding = true;
        }

        if (controller.isGrounded)
        {
            if (isStanding)
            {
                meshFilter.mesh = idleFrame;
                walkParticleSystem.gameObject.SetActive(false);
            }
            else
            {
                walkParticleSystem.gameObject.SetActive(true);
            }

            moveDirection  = new Vector3(hftInput.GetAxis("Horizontal") + Input.GetAxis("Horizontal"), 0, 0);
            moveDirection  = transform.TransformDirection(moveDirection);
            moveDirection *= speed;
            if (Input.GetKeyDown(KeyCode.Space))
            {
                jTimer = 0.09f;
            }

            if (jTimer > 0)
            {
                if (Input.GetKeyUp(KeyCode.Space) || hftInput.GetButtonUp("Fire1"))
                {
                    jTimer = 0;
                    audioSource.PlayOneShot(small_jump);
                    Destroy((Instantiate(jumpParticle, this.transform.position, Quaternion.identity) as ParticleSystem).transform.gameObject, 1.5f);
                    meshFilter.mesh = jumpFrame;
                    moveDirection.y = jumpSpeed * 0.75f;
                }
                else
                {
                    jTimer -= Time.deltaTime;
                    if (jTimer <= 0)
                    {
                        jTimer = 0;
                        audioSource.PlayOneShot(small_jump);
                        Destroy((Instantiate(jumpParticle, this.transform.position, Quaternion.identity) as ParticleSystem).transform.gameObject, 1.5f);
                        meshFilter.mesh = jumpFrame;
                        moveDirection.y = jumpSpeed;
                    }
                }
            }

            if (onSpring)
            {
                audioSource.PlayOneShot(small_jump);
                meshFilter.mesh = jumpFrame;
                moveDirection.y = jumpSpeed * 1.5f;
                onSpring        = false;

                Sequence cameraPushPop = DOTween.Sequence();
                cameraPushPop.easeOvershootOrAmplitude = 0.2f;
                cameraPushPop.Append(mainCamera.DOFieldOfView(50, 0.2f).SetEase(Ease.OutCirc));
                cameraPushPop.Append(mainCamera.DOFieldOfView(55, 0.35f).SetEase(Ease.InOutBack));
            }
        }
        else
        {
            walkParticleSystem.gameObject.SetActive(false);
            moveDirection    = new Vector3(hftInput.GetAxis("Horizontal") + Input.GetAxis("Horizontal"), moveDirection.y, 0);
            moveDirection    = transform.TransformDirection(moveDirection);
            moveDirection.x *= speed;
        }

        moveDirection.y -= gravity * Time.deltaTime;
        controller.Move(moveDirection * Time.deltaTime);

        if (isDead != true)
        {
            if (Time.time > nextFrameChange)
            {
                nextFrameChange += period;
                if (isStanding == false &&
                    controller.isGrounded == true)
                {
                    runAnimation();
                }
            }
        }
    }