Guest User

Untitled

a guest
Nov 23rd, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. void Start () {
  2. // Rigidbody2D
  3. body = GetComponent<Rigidbody2D> ();
  4. }
  5.  
  6. void Update () {
  7. // Main Camera
  8. mainView = Camera.main;
  9.  
  10. // Mouse Position
  11. var mousePosition = mainView.ScreenToWorldPoint (Input.mousePosition);
  12. Quaternion rotate = Quaternion.LookRotation (transform.position - mousePosition, Vector3.forward);
  13.  
  14. // Rotation
  15. transform.rotation = rotate;
  16. transform.eulerAngles = new Vector3 (0, 0, transform.eulerAngles.z);
  17.  
  18. // Reset Rigidbody2D
  19. body.velocity = Vector2.zero;
  20. body.angularVelocity = 0;
  21.  
  22. // New Position
  23. var position = new Vector2 (transform.up.x, transform.up.y) * speed * Time.deltaTime;
  24.  
  25. // Mouse Button Down
  26. if (Input.GetMouseButtonDown (0)) {
  27. pressed = true;
  28. }
  29.  
  30. // Mouse Button Up
  31. if (Input.GetMouseButtonUp (0)) {
  32. pressed = false;
  33. }
  34.  
  35. // Move Player
  36. if (pressed) {
  37. body.MovePosition (body.position + position);
  38. }
  39. }
Add Comment
Please, Sign In to add comment