Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class NewBehaviourScript : MonoBehaviour
  6. {
  7. public float moveSpeed;
  8. public float jumpHeight;
  9. Rigidbody2D rb;
  10.  
  11. void Start()
  12. {
  13. rb = GetComponent<Rigidbody2D>();
  14. }
  15.  
  16. void Update()
  17. {
  18. if (Input.GetKeyDown(KeyCode.Space))
  19. {
  20. rb.velocity = new Vector2(rb.velocity.x, jumpHeight);
  21. }
  22.  
  23. if (Input.GetKey(KeyCode.D))
  24. {
  25. rb.velocity = new Vector2(moveSpeed, rb.velocity.y);
  26. }
  27.  
  28. if (Input.GetKey(KeyCode.A))
  29. {
  30. rb.velocity = new Vector2(-moveSpeed, rb.velocity.y);
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement