// Update is called once per frame void Update() { if (!hurt && !freeze) { if (networkObject.IsOwner) { moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); moveDirection *= speed; if (!charCon.isGrounded) { moveDirection += new Vector3(0, -gravity, 0); } charCon.Move(moveDirection * Time.deltaTime); if (!attacking) { plane = new Plane(Vector3.up, transform.position); Ray ray = cam.GetMouseRay(); float hit; plane.Raycast(cam.GetMouseRay(), out hit); transform.LookAt(ray.GetPoint(hit)); } } if (Input.GetKeyDown(KeyCode.Q)) { if (!mouseLocked) { Cursor.lockState = CursorLockMode.Confined; mouseLocked = true; } else { Cursor.lockState = CursorLockMode.None; mouseLocked = false; } } if (Input.GetMouseButtonDown(0)) { animator.SetInteger("playerState", 1); timeOfPress = Time.time; attacking = true; } if (!Input.GetMouseButton(0) && Time.time - timeOfPress > 0.2f) { animator.SetInteger("playerState", 2); attacking = false; attackHitbox.Attack(); } } if (!networkObject.IsOwner) { transform.position = networkObject.position; return; } networkObject.position = transform.position; }
void GetInput() { var newPosition = rb2D.position; var currentDirection = direction; if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) { newPosition += speed * Time.deltaTime * Vector2.up; direction = HitboxController.Direction.Up; } else if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) { newPosition += speed * Time.deltaTime * Vector2.down; direction = HitboxController.Direction.Down; } if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) { newPosition += speed * Time.deltaTime * Vector2.left; direction = HitboxController.Direction.Left; } else if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) { newPosition += speed * Time.deltaTime * Vector2.right; direction = HitboxController.Direction.Right; } if (currentDirection != direction) { attackController.TurnOffHitboxes(); } playerRenderer.sprite = idleSprites[(int)direction]; if (Input.GetKey(KeyCode.Space)) { attackController.Attack(direction, attackLength); } rb2D.MovePosition(newPosition); }