Advertisement
dantepw

Unity movement

Aug 11th, 2014
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. ~~~~~~~~~~~~~~~~~~ PRIMEIRA FORMA:~~~~~~~~~~~~~~~~
  2.  
  3.  
  4. public float maxSpeed = 10;
  5. //andando para esquerda
  6. if (Input.GetKey("left") || Input.GetKey ("a"))
  7. {
  8. transform.position -= Vector3.right * maxSpeed * Time.deltaTime;
  9. }
  10.  
  11. //andando para direita
  12. if (Input.GetKey ("right") || Input.GetKey ("d"))
  13. {
  14. transform.position += Vector3.right * maxSpeed * Time.deltaTime;
  15. }
  16.  
  17. ~~~~~~~~~~~~~~~~~~~~~~~~SEGUNDA FORMA~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18.  
  19. //esquerda
  20. if (Input.GetAxisRaw ("Horizontal") > 0)
  21. {
  22. transform.Translate (Vector2.right * maxSpeed * Time.deltaTime);
  23. }
  24.  
  25. //direita
  26. if (Input.GetAxisRaw ("Horizontal") < 0)
  27. {
  28. transform.Translate (-Vector2.right * maxSpeed * Time.deltaTime);
  29. }~
  30.  
  31. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~TERCEIRA FORMA~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  32. float move = Input.GetAxis ("Horizontal");
  33. rigidbody2D.velocity = new Vector2 (move * maxSpeed, rigidbody2D.velocity.y);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement