Guest User

Untitled

a guest
Apr 15th, 2016
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. The `else if` is the problem. With the `else if`, it **wont** run the rest of the code in the else if any one in the top is true. What you do is **remove** the else ifs and simply use multiple if statements.
  2.  
  3. private void MovePlayer()
  4. {
  5. if (Input.GetKey(KeyCode.W)) // Up
  6. {
  7. if (Input.GetKey(KeyCode.A)) //Up and left
  8. {
  9. rigidB.velocity += new Vector3(-moveSpeed, 0, moveSpeed);
  10. }
  11. else if (Input.GetKey(KeyCode.D)) //Up and right
  12. {
  13. rigidB.velocity += new Vector3(moveSpeed, 0, moveSpeed);
  14. }
  15. else
  16. {
  17. rigidB.velocity += new Vector3(0, 0, moveSpeed);
  18. }
  19. }
  20. if (Input.GetKey(KeyCode.S)) // Down
  21. {
  22. rigidB.velocity += new Vector3(0, 0, -moveSpeed);
  23. }
  24. if (Input.GetKey(KeyCode.A)) // Left
  25. {
  26. rigidB.velocity += new Vector3(-moveSpeed, 0, 0);
  27. }
  28. if (Input.GetKey(KeyCode.D)) // Right
  29. {
  30. rigidB.velocity += new Vector3(moveSpeed, 0, 0);
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment