private void OnGUI() { // 충돌 정보 GUILayout.Label("충돌 : " + collisionFlags.ToString()); GUILayout.Label("현재 속도 : " + GetVelocitySpeed().ToString()); // 캐릭터컨트롤러 컴포넌트를 찾았고, 현재 내 캐릭터의 이동속도가 0이 아니라면 if (characterController != null && characterController.velocity != Vector3.zero) { // 현재 내 캐릭터가 이동하는 방향 (+크기) GUILayout.Label("current Velocity Vector : " + characterController.velocity.ToString()); // 현재 내 속도 GUILayout.Label("current Velocity Magnitude : " + characterController.velocity.magnitude.ToString()); } }
public void Update() { // Get the mouse pressed position in world. if ((Input.GetAxis("Fire1")>0 || Input.GetAxis("Fire2")>0) && !isMouseHovering(Input.mousePosition, guiRect, guiRectYFromBottom)) { Ray ray = myCamera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray,out hit,rayCastDisntance, layerMask)) { currentMoveToPos = hit.point; // Keep target height same as player height for accuracy. currentMoveToPos.y = myTransform.position.y; //Check if character not already at target position then move if(Vector3.Distance(myTransform.position, currentMoveToPos) > distanceError) { hasTargetPosition = true; } } buttonDown = true; } else { buttonDown = false; } // Make sure the character stays on the ground. ApplyGravity (); // Keep target height same as player height for accuracy. currentMoveToPos.y = myTransform.position.y; // Was a successful move enabled. if(hasTargetPosition) { // Look at target. myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(currentMoveToPos - myTransform.position), rotationSpeed * Time.deltaTime); // Move to target location. collisionFlags = controller.Move((myTransform.forward * moveSpeed * Time.deltaTime)+( new Vector3 (0, verticalSpeed, 0))); if(animator != null) { animator.SetBool("run", true); } // Check if side was hit and stop character. if(collisionFlags.ToString().Equals("5")) { hasTargetPosition = false; // Set character to previous position so animation of running/walking happens next. collisionFlags = controller.Move((myTransform.forward * -1 * moveSpeed * Time.deltaTime)+( new Vector3 (0, verticalSpeed, 0))); if(animator != null) { animator.SetBool("run", false); } } // Calculate distance to target location and stop if in range. if(Vector3.Distance(myTransform.position, currentMoveToPos) <= distanceError && !buttonDown) { hasTargetPosition = false; if(animator != null) { animator.SetBool("run", false); } } } else if(verticalSpeed != 0.0f) { controller.Move(new Vector3 (0, verticalSpeed, 0)); } }
void OnGUI() { GUI.color = Color.red; GUI.Label(new Rect(10, 10, 100, 20), "state : " + _characterState.ToString()); GUI.Label(new Rect(10, 30, 100, 20), "collision flag : " + collisionflag.ToString()); }