Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #pragma strict
  2. private var flipRight = false;
  3. var mainCamera : Camera;
  4. var Player : GameObject;
  5. var cursor : Transform;
  6. public var distance = 10.0;
  7.  
  8. function PlayerFlipRight () {
  9. flipRight = true;
  10. }
  11.  
  12. function PlayerFlipLeft () {
  13. flipRight = false;
  14. }
  15.  
  16. function FixedUpdate () {
  17.  
  18. var centerOfScreen : float = (Screen.width / 2);
  19. var posC = Vector3(Input.mousePosition.x, Input.mousePosition.y, distance);
  20.  
  21. posC = mainCamera.ScreenToWorldPoint(posC);
  22. cursor.position = posC;
  23. Screen.showCursor = false;
  24.  
  25. if(Input.mousePosition.x > centerOfScreen){
  26. flipRight = true;
  27. transform.localScale.y = 1;
  28. Player.BroadcastMessage("FlipRight", SendMessageOptions.DontRequireReceiver);
  29. }
  30. else if(Input.mousePosition.x < centerOfScreen){
  31. flipRight = false;
  32. transform.localScale.y = -1;
  33. Player.BroadcastMessage("FlipLeft", SendMessageOptions.DontRequireReceiver);
  34. }
  35.  
  36. if(flipRight){
  37. transform.localScale.y = 1;
  38.  
  39. var pos = mainCamera.WorldToScreenPoint(transform.position);
  40. var dir = Input.mousePosition - pos;
  41. var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
  42. transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
  43.  
  44. }
  45. else {
  46. transform.localScale.y = -1;
  47.  
  48. pos = mainCamera.WorldToScreenPoint(transform.position);
  49. dir = Input.mousePosition - pos;
  50. angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
  51. transform.rotation = Quaternion.AngleAxis(-angle, Vector3.forward);
  52.  
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement