void Start() { playerState = ControlWalkState.Idle; characterController = GetComponent <CharacterController>(); playerDir = GetComponent <PlayerDir>(); playerAttack = GetComponent <PlayerAttack>(); }
public void moveMouse() { // 使用上下方向键或者W、S键来控制前进后退 if (Input.GetAxisRaw("Vertical") != 0 || Input.GetAxisRaw("Horizontal") != 0) { pa.bigstate = PlayerState.ControlWalkState; state = ControlWalkState.Moving; speed = 5.0f; if (Input.GetKey(KeyCode.LeftShift)) { state = ControlWalkState.Run; speed = 8.0f; } } else { state = ControlWalkState.Idle; } float translation = Input.GetAxis("Vertical") * speed * Time.deltaTime; //使用左右方向键或者A、D键来控制左右旋转 float rotation = Input.GetAxis("Horizontal") * 3 * Time.deltaTime; if (Cursor.visible == false) { transform.Rotate(0, Input.GetAxis("Mouse X") * 50 * Time.deltaTime, 0); } transform.Translate(0, 0, translation); transform.Translate(rotation, 0, 0); //绕Y轴旋转 }
// Update is called once per frame void Update () { if (playerAttack.state == PlayerState.ControlWalk) { //the distance between the current position and the target position float distance = Vector3.Distance (dir.targetPosition, transform.position); //not arrive the target position, use character controller move the character if (distance > 0.3f) { //the character is moving now isMove = true; //move the character controller.SimpleMove (transform.forward * speed); //change the animation, change to the walk state = ControlWalkState.Moving; } else { //the character is standing now isMove = false; //change the animation to the idle state = ControlWalkState.Idle; } } // float h = Input.GetAxis ("Horizontal"); // float v = Input.GetAxis ("Vertical"); // if (Mathf.Abs (h) > 0.1f || Mathf.Abs (v) > 0.1) { // animator.CrossFade ("Sword-Run"); // Vector3 targetDir = new Vector3 (h, 0, v); // transform.LookAt (targetDir + transform.position); // controller.SimpleMove (transform.forward * speed); // } }
// Update is called once per frame void Update() { if (attack.state == PlayerState.ControlWalk) { float distance = Vector3.Distance(dir.targetPosition, transform.position); if (distance > 0.3f) { isMoving = true; playerState = ControlWalkState.Moving; controller.SimpleMove(transform.forward * speed); } else { isMoving = false; playerState = ControlWalkState.Idle; } } }
// Update is called once per frame void Update() { speed = originalspeed + ((float)PlayerStatus._instance.sum_speed / 100f); if (attack.state == PlayerState.ControlWalk && attack.state != PlayerState.Death && attack.state != PlayerState.SkillAttack) { float distance = Vector3.Distance(dir.targetPos, transform.position); if (distance > 0.3f) { isMove = true; state = ControlWalkState.Moving; controller.SimpleMove(transform.forward * speed); } else { isMove = false; state = ControlWalkState.Idle; } } }
void Update() { if (playerAttack.state != PlayerState.ControlWalk) { return; } float distance = Vector3.Distance(transform.position, playerDir.targetPosition); if (distance > 0.4f) { isMoving = true; characterController.SimpleMove(transform.forward * speed); playerState = ControlWalkState.Run; } else { isMoving = false; playerState = ControlWalkState.Idle; } }