// Update is called once per frame void Update() { GetComponent <Rigidbody2D>().velocity = new Vector2(CrossPlatformInputManager.GetAxisRaw("Horizontal") * MoveSpeed, CrossPlatformInputManager.GetAxisRaw("Vertical") * MoveSpeed); GetComponent <Animator>().SetFloat("direction", GetComponent <Rigidbody2D>().velocity.y); if (GetComponent <Rigidbody2D>().velocity.x < 0) { GetComponent <SpriteRenderer>().flipX = true; } else if (GetComponent <Rigidbody2D>().velocity.x > 0) { GetComponent <SpriteRenderer>().flipX = false; } }
void Update() { horizonCrossInput = CrossPlatformInputManager.GetAxisRaw("Horizontal"); vertiCrossInput = CrossPlatformInputManager.GetAxisRaw("Vertical"); CrossMove(horizonCrossInput, vertiCrossInput); PlayerJump(isGrounded); //if (jumpTimer > jumpInterval) //{ // PlayerJump(isGrounded); // jumpTimer = 0.0f; //} //jumpTimer += Time.deltaTime; //playerRigidbody.AddForce(-Vector3.up*3, ForceMode.VelocityChange); }
// Update is called once per frame void Update() { movement_vector = new Vector2(CrossPlatformInputManager.GetAxisRaw("Horizontal"), CrossPlatformInputManager.GetAxisRaw("Vertical")); if (movement_vector != Vector2.zero) { anim.SetBool("isWalking", true); anim.SetFloat("x", movement_vector.x); anim.SetFloat("y", movement_vector.y); } else { anim.SetBool("isWalking", false); } }
void FixedUpdate() { if (gamePausedManager == null || !gamePausedManager.IsGamePaused) { float h = 0; float v = 0; h = CrossPlatformInputManager.GetAxisRaw("Horizontal"); v = CrossPlatformInputManager.GetAxisRaw("Vertical"); Move(h, v); Turning(); Animate(h, v); } }
void Update() { // 右・左 float x = CrossPlatformInputManager.GetAxisRaw("Horizontal"); // 上・下 float y = CrossPlatformInputManager.GetAxisRaw("Vertical"); // 移動する向きを求める //Vector2 direction = new Vector2(x, y).normalized; Vector2 direction = new Vector2(x, y); // 移動の制限 Move(direction); }
// Update is called once per frame void FixedUpdate() { input = new Vector3(CrossPlatformInputManager.GetAxisRaw("Horizontal"), 0, CrossPlatformInputManager.GetAxisRaw("Vertical")); if (GetComponent <Rigidbody>().velocity.magnitude < maxSpeed) { GetComponent <Rigidbody>().AddRelativeForce(input * moveSpeed); } if (transform.position.y < -2) { Die(); } //Physics.gravity = Physics.Raycast(transform.position, Vector3.down, .6f) ? Vector3.zero : new Vector3(0, -9.5f, 0); }
void Update() { #if UNITY_IOS || UNITY_ANDROID Vector2 input = TouchLib.GetSwipe2D(); inputVH = input; CrossPlateformButton(); #else inputVH.x = CrossPlatformInputManager.GetAxisRaw("Horizontal"); inputVH.y = CrossPlatformInputManager.GetAxisRaw("Vertical"); #endif currentVH = Vector2.SmoothDamp(currentVH, inputVH, ref currentVelocity, smoothTime, float.MaxValue, Time.deltaTime); StandaredKeyInput(); }
void FixedUpdate() { // Store the input axes. float h = CrossPlatformInputManager.GetAxisRaw("Horizontal1"); float v = CrossPlatformInputManager.GetAxisRaw("Vertical1"); // Move the player around the scene. Move(h, v); // Turn the player according to WASD and Joystick Turning(h, v); // Animate the player Animate(h, v); }
// Update is called once per frame void Update() { aim.x = CrossPlatformInputManager.GetAxisRaw("MouseX"); aim.y = CrossPlatformInputManager.GetAxisRaw("MouseY"); //Debug.Log("aim.sqrMagnitude:" + aim.sqrMagnitude.ToString()); var aimDirection = aim.normalized; float angleInDeg = Mathf.Atan2(aimDirection.y, aimDirection.x) * Mathf.Rad2Deg; transform.eulerAngles = new Vector3(0, 0, angleInDeg); if (aim.sqrMagnitude > 0.6f) { shootingSystem.ShootBullet(); } }
void Animating(float h, float v) { bool running = h != 0 || v != 0; anim.SetBool("isRun", running); //用GetAxisRaw判斷是否按到移動鍵,是的話執行以下程式,放開可以保留角度狀態,也能避免NaN的狀況 if (CrossPlatformInputManager.GetAxisRaw("Vertical") != 0 || CrossPlatformInputManager.GetAxisRaw("Horizontal") != 0) { //三角函數計算 angle_Sum = Mathf.Atan2(h, v) / (Mathf.PI / 180); //角色轉向 transform.eulerAngles = new Vector3(transform.eulerAngles.x, angle_Sum, transform.eulerAngles.z); } }
// Update is called once per frame void Update() { input = new Vector3(CrossPlatformInputManager.GetAxisRaw("Horizontal"), 0, CrossPlatformInputManager.GetAxisRaw("Vertical")); //input = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")); if (GetComponent <Rigidbody>().velocity.magnitude < maxSpeed) { GetComponent <Rigidbody>().AddForce(input * moveSpeed); } if (transform.position.y < 0) { Death(); } }
// Update is called once per frame void Update() { Vector2 moveInput = new Vector2(CrossPlatformInputManager.GetAxisRaw("Horizontal"), CrossPlatformInputManager.GetAxisRaw("Vertical")); moveAmount = moveInput.normalized * speed; if (moveInput != Vector2.zero) { anim.SetBool("isRunning", true); } else { anim.SetBool("isRunning", false); } }
void FixedUpdate() { // Store the input axes. float h = CrossPlatformInputManager.GetAxisRaw("Horizontal"); float v = CrossPlatformInputManager.GetAxisRaw("Vertical"); // Move the player around the scene. Move(h, v); // Turn the player to face the mouse cursor. Turning(); // Animate the player. Animating(h, v); }
// Update is called once per frame void Update() { hmove = CrossPlatformInputManager.GetAxisRaw("Horizontal") * runSpeed; if (hmove != 0) { animator.SetBool("isWalking", true); } if (CrossPlatformInputManager.GetButtonDown("Jump")) { animator.SetBool("isJumping", true); sounds.PlayAudioClip(1); } }
private Vector2 GetDirection() { #if MOBILE_INPUT Vector2 result = new Vector2( CrossPlatformInputManager.GetAxisRaw("Horizontal"), CrossPlatformInputManager.GetAxisRaw("Vertical") ); #else Vector2 result = new Vector2( Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical") ); #endif return(result); }
void Update() { VelocityX = CrossPlatformInputManager.GetAxisRaw("Horizontal"); //Move the player RigidBody.velocity += new Vector2(VelocityX * MoveSpeed, 0); if (VelocityX > 0.05) { PlayerAnim.Play("PlayerWalkingRight"); } else if (VelocityX < -0.05) { PlayerAnim.Play("PlayerWalkingLeft"); } else { //VelocityY = 0; //VelocityX = 0; PlayerAnim.Play("PlayerStill"); } //Debug.Log(VelocityX + "," + VelocityY); if (CrossPlatformInputManager.GetButtonDown("Fire1")) { //Debug.Log("Button Pressed"); if (BombPlaced < BombCapacity) { //Pos = new Vector2(Player.position.x, Player.position.y); //float posX = (Pos.x / 50) + 25; //float posY = (Pos.y / 50) + 25; //Pos.x = posX; //Pos.y = posY; //Debug.Log("Button Press"); Instantiate(Bomb, Floor, Player.rotation); StartCoroutine(ChangeScene()); } CrossPlatformInputManager.SetButtonUp("Fire1"); } //floorCollider = gameObject.GetComponent<FloorCollider>(); //floor = floorCollider.Floor; //Debug.Log(floor); }
/* * ========Update============================================ */ /// <summary> /// 把輸入存起來,漸進式的用GetAxis,按鍵式的用GetAxisRaw /// </summary> void GetInput() { if (Player.bBlockInput == false) { if (Player.bCanMove) { m_fVInput = CrossPlatformInputManager.GetAxis(FORWARD_AXIS); m_fVInputAbs = Mathf.Abs(m_fVInput); m_fHInput = CrossPlatformInputManager.GetAxis(TURN_AXIS); m_fHInputAbs = Mathf.Abs(m_fHInput); m_fMoveInput = Mathf.Clamp01(m_fVInputAbs + m_fHInputAbs); } else { m_fVInput = m_fHInput = m_fVInputAbs = m_fHInputAbs = m_fMoveInput = 0; } if (Player.bCanJump && bGrounded) { m_fJInput = CrossPlatformInputManager.GetAxisRaw("Jump"); } else { m_fJInput = 0; } if (Player.bCanDash) { m_fDInput = CrossPlatformInputManager.GetAxisRaw(DASH_AXIS); } else { m_fDInput = 0; } //能夠攻擊時才能有效輸入 if (Player.bCanAttack) { m_fLAInput = CrossPlatformInputManager.GetAxisRaw("Fire1"); m_fHAInput = CrossPlatformInputManager.GetAxisRaw("Fire2"); } else { m_fLAInput = m_fHAInput = 0; } } else { m_fVInput = m_fHInput = m_fJInput = m_fDInput = m_fLAInput = m_fHAInput = 0; } }
private void CarIndexSelecting_2P() { if (CrossPlatformInputManager.GetAxisRaw("Crosswise_2") > 0) { if (!_nonUpFlag2) { if (_carIndex2 < _idxMax - 1) { _carIndex2++; _carObj_2P[_carIndex2].gameObject.transform.rotation = _carObj_2P[_carIndex2 - 1].gameObject.transform.rotation; _nonUpFlag2 = true; } else { _carIndex2 = 0; _carObj_2P[_carIndex2].gameObject.transform.rotation = _carObj_2P[_idxMax - 1].gameObject.transform.rotation; _nonUpFlag2 = true; } } } else { _nonUpFlag2 = false; } if (CrossPlatformInputManager.GetAxisRaw("Crosswise_2") < 0) { if (!(_nonDownFlag2)) { if (_carIndex2 > 0) { _carIndex2--; _carObj_2P[_carIndex2].gameObject.transform.rotation = _carObj_2P[_carIndex2 + 1].gameObject.transform.rotation; _nonDownFlag2 = true; } else { _carIndex2 = _idxMax - 1; _carObj_2P[_carIndex2].gameObject.transform.rotation = _carObj_2P[0].gameObject.transform.rotation; _nonDownFlag2 = true; } } } else { _nonDownFlag2 = false; } }
// Update is called once per frame void Update() { //position.x += Input.GetAxis("Horizontal") * speed * Time.deltaTime; //if (Input.touchCount > 0) { //} boost.SetActive(false); if (Input.GetKeyDown(KeyCode.UpArrow)) { if (start == false) { start = true; Time.timeScale = 1; } if (Time.timeScale == 1) { gameObject.GetComponent <Rigidbody2D>().AddForce(transform.up * jump); whoosh.Play(); boost.SetActive(true); } } if (start == true) { if (earth != null) { if (earth.transform.position.y > -15) { earth.transform.position -= transform.up * Time.deltaTime * 2.2f; } else { Destroy(earth); } } } if (!(gameObject.transform.position.y > -8 && gameObject.transform.position.y < 8)) { Time.timeScale = 0; //Debug.Log ("GAME OVER - LOST IN OBLIVION"); GameOver(); } gameObject.transform.position += CrossPlatformInputManager.GetAxisRaw("Horizontal") * transform.right * Time.deltaTime * steerspeed; }
private void CarIndexSelecting() { if (CrossPlatformInputManager.GetAxisRaw("Horizontal") > 0) { if (!_nonUpFlag) { if (_carIndex < _idxMax - 1) { _carIndex++; _carObj[_carIndex].gameObject.transform.rotation = _carObj[_carIndex - 1].gameObject.transform.rotation; _nonUpFlag = true; } else { _carIndex = 0; _carObj[_carIndex].gameObject.transform.rotation = _carObj[_idxMax - 1].gameObject.transform.rotation; _nonUpFlag = true; } } } else { _nonUpFlag = false; } if (CrossPlatformInputManager.GetAxisRaw("Horizontal") < 0) { if (!(_nonDownFlag)) { if (_carIndex > 0) { _carIndex--; _carObj[_carIndex].gameObject.transform.rotation = _carObj[_carIndex + 1].gameObject.transform.rotation; _nonDownFlag = true; } else { _carIndex = _idxMax - 1; _carObj[_carIndex].gameObject.transform.rotation = _carObj[0].gameObject.transform.rotation; _nonDownFlag = true; } } } else { _nonDownFlag = false; } }
public void Get() { if (!m_Enabled) { Value = 0f; return; } if (!m_GettingInput) { return; } bool positiveHeld = false; bool negativeHeld = false; float value = CrossPlatformInputManager.GetAxisRaw(k_AxisToName[(int)controllerAxis]); RealValue = Util.Normalize(value, Constants.JOYSTICK_AXIS_MAX_VALUE); positiveHeld = Input.GetKey(positive); negativeHeld = Input.GetKey(negative); if (!positiveHeld) { positiveHeld = value > Single.Epsilon; } if (!negativeHeld) { negativeHeld = value < -Single.Epsilon; } if (positiveHeld == negativeHeld) { Value = 0f; } else if (positiveHeld) { Value = 1f; } else { Value = -1f; } ReceivingInput = positiveHeld || negativeHeld; }
private void Update() { rotDir = CrossPlatformInputManager.GetAxisRaw("Horizontal"); if (Input.touchCount > 0 && rotDir == 0.0f) { Touch touch = Input.GetTouch(0); if (touch.position.x < Screen.width / 2) { rotDir = -1; } else { rotDir = 1; } } }
void Movement() { // Store the input axes. float h = CrossPlatformInputManager.GetAxisRaw("Horizontal"); float v = CrossPlatformInputManager.GetAxisRaw("Vertical"); Vector3 movement = new Vector3(); movement.Set(h, 0f, v); // Normalise the movement vector and make it proportional to the speed per second. movement = movement.normalized * _playerNode.speedComponent.speed * Time.deltaTime; // Move the player to it's current position plus the movement. _playerNode.rigidBodyComponent.rigidbody.MovePosition(_playerNode.positionComponent.position + movement); }
private void Update() { // read inputs h = CrossPlatformInputManager.GetAxisRaw("Horizontal"); v = CrossPlatformInputManager.GetAxisRaw("Vertical"); if (CrossPlatformInputManager.GetButtonDown("Push")) { push.Apply(); } if (CrossPlatformInputManager.GetButtonDown("Fire1")) { grab.Apply(); } }
// Update is called once per frame void Update() { //laserLine.SetPosition(0, LaserBeamOrigin.transform.position); #if !MOBILE_INPUT if (Input.GetButtonDown("Fire1") && isShooting == false && isEnabled == true) { Shoot(); } #else if (CrossPlatformInputManager.GetAxisRaw("Mouse X") != 0 || CrossPlatformInputManager.GetAxisRaw("Mouse Y") != 0) { Shoot(); } #endif }
//每帧执行一次,用于获取玩家输入并控制角色的行为 void Update() { //当游戏状态为游戏进行中时 if (GameManager.gm == null || GameManager.gm.gameState == GameManager.GameState.Playing) { float h = CrossPlatformInputManager.GetAxisRaw("Horizontal"); //获取玩家水平轴上的输入 float v = CrossPlatformInputManager.GetAxisRaw("Vertical"); //获取玩家垂直轴上的输入 Move(h, v); //根据玩家的输入控制角色移动 float rv = CrossPlatformInputManager.GetAxisRaw("Mouse X"); //获取玩家鼠标垂直轴上的移动 float rh = CrossPlatformInputManager.GetAxisRaw("Mouse Y"); //获取玩家鼠标水平轴上的移动 Rotate(rh, rv); //根据玩家的鼠标输入控制角色转向 Jump(isGrounded); //玩家的跳跃函数 } }
void DoGetAxis() { var axisValue = 0f; #if CROSS_PLATFORM_INPUT axisValue = CrossPlatformInputManager.GetAxisRaw(axisName.Value); #endif // if variable set to none, assume multiplier of 1 if (!multiplier.IsNone) { axisValue *= multiplier.Value; } store.Value = axisValue; }
void FixedUpdate() { // almacenar los ejes de entrada float h = CrossPlatformInputManager.GetAxisRaw("Horizontal"); float v = CrossPlatformInputManager.GetAxisRaw("Vertical"); // movimiento del jugador alrededor de la escena Move(h, v); // girar al jugador con los movimientos del cursor Turning(); // animacion del jugador Animating(h, v); }
public void Movement() { float move = CrossPlatformInputManager.GetAxisRaw("Horizontal"); grounded = IsGrounded(); Flip(move); playerAnimation.Move(move); if ((Input.GetKeyDown(KeyCode.Space) || CrossPlatformInputManager.GetButtonDown("B_Button")) && IsGrounded()) { rgb.velocity = new Vector2(rgb.velocity.x, jumpForce); playerAnimation.Jump(true); StartCoroutine(ResetJumpNeededCo()); } rgb.velocity = new Vector2(move * speed, rgb.velocity.y); }
private void RunUpDown() { float controlThrowUD = CrossPlatformInputManager.GetAxisRaw("Vertical"); Vector2 playerVelocityUpDown = new Vector2(myRigidBody2D.velocity.x, controlThrowUD * runSpeed); myRigidBody2D.velocity = playerVelocityUpDown; bool isRunning = Mathf.Abs(myRigidBody2D.velocity.y) > Mathf.Epsilon; if (Input.GetKeyDown(KeyCode.S) == true) { myAnimator.SetBool("IsRunningFront", isRunning); myAnimator.SetBool("IsRunningBack", false); myAnimator.SetBool("IsRunningRight", false); myAnimator.SetBool("IsRunningLeft", false); } }