Guest User

Untitled

a guest
Feb 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1.  
  2. // ## Sricpt to allow images to be swiped across the screen by a user on the iPhone ##//
  3.  
  4.  
  5. // New image position
  6. var newXPosition : float;
  7.  
  8. // Slow swipe movement
  9. var speed : int = 4;
  10.  
  11. // Default Position
  12. var posY : float = 0.275;
  13. var posZ : float = -6.87;
  14.  
  15.  
  16. //currentScreen
  17. static var currentScreen : String;
  18.  
  19. //Images
  20. var image_1 : GameObject;
  21.  
  22. //Smooth image flip/rotation
  23. var rotationSmooth : float = 10;
  24.  
  25. function Start()
  26. {
  27. newXPosition = transform.position.x;
  28.  
  29. }
  30. function Update ()
  31. {
  32.  
  33.  
  34. var count = Input.touchCount;
  35.  
  36. //check for each touch
  37. for (var i: int = 0; i < count; i++)
  38. {
  39. var touch : Touch = Input.GetTouch(i);
  40.  
  41. // Check if the user is swiping
  42. if (touch.phase == TouchPhase.Moved )
  43.  
  44. {
  45. // get new position
  46. newXPosition += touch.deltaPosition.x * speed * Time.deltaTime;
  47.  
  48.  
  49. }
  50.  
  51. }
  52.  
  53.  
  54. transform.position = Vector3(Mathf.Lerp(transform.position.x , newXPosition,Time.deltaTime * 1) , posY , posZ);
  55.  
  56. if(Input.GetMouseButtonDown(0))
  57. {
  58. wantedRotation = image_1.transform.rotation * Quaternion.Euler(0, 180, 0);
  59.  
  60.  
  61. }
  62.  
  63.  
  64.  
  65. image_1.transform.rotation = Quaternion.RotateTowards(image_1.transform.rotation, wantedRotation, rotationSmooth * Time.deltaTime);
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72. }
Add Comment
Please, Sign In to add comment