SpinInput.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //This asset was uploaded by https://unityassetcollection.com
  2. /// ProFlares - v1.08 - Copyright 2014-2015 All rights reserved - ProFlares.com
  3. /// <summary>
  4. /// SpinInput.cs
  5. /// Rotates a transform based on click dragging. Works on ether X or Y Axis. Y Axis can be limited.
  6. /// </summary>
  7. using UnityEngine;
  8. using System.Collections;
  9. namespace ProFlares {
  10. public class SpinInput : MonoBehaviour {
  11. private Transform thisTransform;
  12. float xVerlo;
  13. float targetVerloX;
  14. float lastX;
  15. float currentX;
  16. float offsetX;
  17. float finalVeloX;
  18. float tempVeloX;
  19. float YVerlo;
  20. float targetVerloY;
  21. float lastY;
  22. float currentY;
  23. float offsetY;
  24. float finalVeloY;
  25. float tempVeloY;
  26. public int cropDist = 180;
  27. public float ResponseTime = 0.2f;
  28. public bool touchMode = true;
  29. void Start () {
  30. thisTransform = transform;
  31. }
  32. public bool X;
  33. public bool Y;
  34. void LateUpdate () {
  35. if(X){
  36. if(Input.GetMouseButtonDown(0)){
  37. // print("MouseDown");
  38. lastX = 0;
  39. currentX = 0;
  40. offsetX = Input.mousePosition.x;
  41. }
  42. if(Input.GetMouseButton(0)){
  43. lastX = currentX;
  44. currentX = Input.mousePosition.x-offsetX;
  45. targetVerloX = (currentX-lastX)*2;
  46. if((currentX-lastX > 1)||(currentX-lastX < -1)){
  47. }
  48. targetVerloX = targetVerloX*3.5f;
  49. }else{
  50. targetVerloX = targetVerloX*0.95f;
  51. }
  52. finalVeloX = Mathf.Lerp(finalVeloX,targetVerloX,20*Time.deltaTime);
  53. thisTransform.Rotate(0,finalVeloX*Time.deltaTime,0);
  54. }
  55. if(Y){
  56. if(Input.GetMouseButtonDown(0)){
  57. // print("MouseDown");
  58. lastY = 0;
  59. currentY = 0;
  60. offsetY = Input.mousePosition.y;
  61. }
  62. if(Input.GetMouseButton(0)){
  63. lastY = currentY;
  64. currentY = Input.mousePosition.y-offsetY;
  65. targetVerloY = (currentY-lastY)*-2;
  66. targetVerloY = targetVerloY*1.5f;
  67. }else{
  68. targetVerloY = targetVerloY*0.95f;
  69. }
  70. finalVeloY = Mathf.Lerp(finalVeloY,targetVerloY,20*Time.deltaTime);
  71. thisTransform.Rotate(finalVeloY*Time.deltaTime,0,0);
  72. Quaternion newrotation = thisTransform.rotation;
  73. newrotation.x = Mathf.Clamp(newrotation.x,-0.1f,0.3f);
  74. thisTransform.rotation = newrotation;
  75. }
  76. }
  77. }
  78. }