//角色移动函数 public void characterMove(float horizontal) { //切换动画状态 changeStatus(horizontal); //切换角色朝向 changeDirection(horizontal); //GetComponent<Rigidbody2D>().AddForce(new Vector2(horizontal * MoveSpeed, 0)); // --last version float lineSpeed = 0; if (Input.GetButton("Sprint") || (CrossPlatform.getInstance() != null && CrossPlatform.getInstance().btn_A_isPressed)) { lineSpeed = horizontal * MoveSpeed; } else { lineSpeed = horizontal * MoveSpeed / 2; } //直接操控刚体的线性速度 m_Rigidbody2D.velocity = new Vector2(lineSpeed, m_Rigidbody2D.velocity.y); //角色脚步音效 playFootPrintSE(horizontal); //角色下落音效 playFallDownSE(); }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state //override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { // //} // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { //加速奔跑动画加速 if (Input.GetButton("Sprint") || (CrossPlatform.getInstance() != null && CrossPlatform.getInstance().btn_A_isPressed)) { animator.speed = 2; } else { animator.speed = 1; } }
public void playFootPrintSE(float horizontal) { if (m_isGrounded && horizontal != 0 && !AudioControler.getInstance().SE_FootNote.isPlaying && !AudioControler.getInstance().SE_FootNote_L.isPlaying) { AudioControler.getInstance().SE_FootNote.Play(); if (Input.GetButton("Sprint") || (CrossPlatform.getInstance() && CrossPlatform.getInstance().btn_A_isPressed)) { AudioControler.getInstance().SE_FootNote_L.PlayDelayed(0.1f); } else { AudioControler.getInstance().SE_FootNote_L.PlayDelayed(0.165f); } } }