Advertisement
Guest User

Untitled

a guest
Nov 16th, 2018
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Player : MonoBehaviour {
  6.  
  7. public GameObject player;
  8. private Vector2 _currentMousePosition;
  9. public Transform target;
  10.  
  11. void Start()
  12. {
  13.  
  14. }
  15.  
  16. void Update()
  17. {
  18. if (Input.GetMouseButtonDown(0))
  19. {
  20.  
  21. Vector3 mousePos = Input.mousePosition;
  22.  
  23. Vector3 objPos = Camera.main.WorldToScreenPoint(transform.position);
  24. mousePos.x -= objPos.x;
  25. mousePos.y -= objPos.y;
  26.  
  27. float angle = Mathf.Atan2(mousePos.y, mousePos.x) * Mathf.Rad2Deg;
  28.  
  29. Debug.Log(angle);
  30.  
  31. if (angle <= 45 && angle >= -45)
  32. {
  33. player.transform.position = new Vector2(player.transform.position.x + 1, player.transform.position.y);
  34. }
  35. if (angle >= 45 && angle <= 135)
  36. {
  37. player.transform.position = new Vector2(player.transform.position.x, player.transform.position.y + 1);
  38. }
  39. if (angle >= 135 && angle <= -135)
  40. {
  41. player.transform.position = new Vector2(player.transform.position.x - 1, player.transform.position.y);
  42. }
  43. if (angle >= -135 && angle <= -45)
  44. {
  45. player.transform.position = new Vector2(player.transform.position.x, player.transform.position.y - 1);
  46. }
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement