/// 控制 向角色正前方移动和角色原地旋转 static void ContorlMove(this TranslateComponent self) { if (self.isCanControl) { self.h = Input.GetAxis("Horizontal"); //获取水平方线 //默认 Horizontal a键 为 -1 d键为 1 self.v = Input.GetAxis("Vertical"); //获取水平方线 //默认 Vertical s键 为 -1 w键为 1 #region //if (Mathf.Abs(EngineerJoyStick.hv2.x) > 10.0f || Mathf.Abs(EngineerJoyStick.hv2.y) > 10.0f) //{ // self.h = EngineerJoyStick.hv2.x / EngineerJoyStick.mRadius; // self.v = EngineerJoyStick.hv2.y / EngineerJoyStick.mRadius; //} //else //{ // self.h = Input.GetAxis("Horizontal"); //获取水平方线 //默认 Horizontal a键 为 -1 d键为 1 // self.v = Input.GetAxis("Vertical"); //获取水平方线 //默认 Vertical s键 为 -1 w键为 1 // //Debug.Log(" move.v: " + move.v ); //} #endregion } self.GetParent <Unit>().GameObject.transform.Translate(0, 0, self.v * self.moveSpeed * Time.deltaTime); self.GetParent <Unit>().GameObject.transform.Rotate(0, self.h * self.roteSpeed, 0); if (self.IsGrounded()) { Debug.Log(" self.IsGrounded(): " + self.IsGrounded()); } }
/// 控制 跳跃 static void ControlJump(this TranslateComponent self) { if (Input.GetButton("Jump") && self.IsGrounded())//如果点击了触发跳跃的键盘按钮的话 { //每点击一次,上升。 上升的中途过程中,如果再次点击,就再次上升。上升到某个临界值,开始下降,下降到地面,就取消Jump。停止Jump运算 if (self.IsJumpUp && self.IsJump) { //刷新起始跳跃速度 self.actuallySpeed = self.jumpSpeed;//每点一次跳跃都要设置初始速度单位 return; } if (self.IsJumpDown && self.IsJump) { //刷新跳跃速度 self.actuallySpeed = self.jumpSpeed;//每点一次跳跃都要设置初始速度单位 self.IsJumpUp = true; self.IsJumpDown = false; return; } self.actuallySpeed = self.jumpSpeed;//每点一次跳跃都要设置初始速度单位 self.IsJump = true; self.IsJumpUp = true; } if (self.IsJump) { if (self.IsJumpUp) //还在上升期 { self.GetParent <Unit>().GameObject.transform.Translate(new Vector3(0, self.actuallySpeed * Time.deltaTime, 0)); self.actuallySpeed -= self.gravity; if (self.actuallySpeed <= 0) { Debug.Log("switch"); self.IsJumpDown = true; self.IsJumpUp = false; } } if (self.IsJumpDown) //朝下 { self.GetParent <Unit>().GameObject.transform.Translate(new Vector3(0, -self.actuallySpeed * Time.deltaTime, 0)); self.actuallySpeed += self.gravity; //加速下落 Position的Y 轴一直在减少 if (self.GetParent <Unit>().GameObject.transform.position.y <= self.gdy) { Vector3 currentPosition = self.GetParent <Unit>().GameObject.transform.position; self.GetParent <Unit>().GameObject.transform.position = new Vector3(currentPosition.x, 0, currentPosition.z); self.IsJumpDown = false; self.IsJump = false; self.actuallySpeed = self.jumpSpeed; } } Debug.Log(" TranslateComponentHelper-229: " + TimeHelper.ClientNow() + " Jump: " + self.GetParent <Unit>().Position); } }