private void FixedUpdate() { if (!isControllable) { Input.ResetInputAxes(); } else { if (isGround) { float h = Input.GetAxis("Horizontal"); float v = Input.GetAxis("Vertical"); moveDirection = new Vector3(h, 0, v); moveDirection *= moveSpeed; moveHorz = Input.GetAxis("Horizontal"); if (moveHorz > 0)//向右转 { rotateDirection = new Vector3(0, 1, 0); } else if (moveHorz < 0)//向左转 { rotateDirection = new Vector3(0, -1, 0); } else { rotateDirection = new Vector3(0, 0, 0); } if (Input.GetButton("Jump"))//跳跃设置 { moveDirection.y = jumpSpeed; } if (Input.GetButton("Boost"))//加速设置 //left shift 键控制 { if (m_WidgetStates) { m_WidgetStates.DemageEnergy(); moveDirection *= fastSpeed; isBoost = true; } } if (Input.GetButtonUp("Boost"))//left shift 键控制 { isBoost = false; } if (Input.GetButton("Duck"))//半蹲状态设置 { controller.height = duckHeight; controller.center = new Vector3(controller.center.x, controller.height / 2 + 0.25f, controller.center.z); moveDirection *= duckSpeed; isDucking = true; } if (Input.GetButtonUp("Duck"))//取消半蹲状态设置 { controller.height = normalHeight; controller.center = new Vector3(controller.center.x, controller.height / 2, controller.center.z); moveDirection *= fastSpeed; isDucking = false; } if (Input.GetKeyDown(KeyCode.P)) { m_WidgetStates.AddHealth(2); } if (Input.GetKeyDown(KeyCode.O)) { m_WidgetStates.ApplayDamage(2); } } moveDirection.y -= gravity * Time.deltaTime; //模拟的重力 controller.transform.Rotate(rotateDirection * Time.deltaTime, rotateSpeed); //玩家的旋转 CollisionFlags flags = controller.Move(moveDirection * Time.deltaTime); //游戏对象的移动,并且返回一个碰撞状态 isGround = ((flags & CollisionFlags.Below) != 0); //根据碰撞判断是否在地面上 } }
private void OnTriggerEnter(Collider other) { widgetStates = GameObject.FindWithTag("Player").GetComponent <WidgetStates>(); widgetStates.ApplayDamage(damageValue); Debug.Log("我是水,你碰到我会死的!"); }