Zoom.cs 985 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /// ProFlares - v1.08 - Copyright 2014-2015 All rights reserved - ProFlares.com
  2. /// <summary>
  3. /// Zoom.cs
  4. /// Attach to a transform, which will then move in on the Z Axis when the mouse wheel is used.
  5. /// </summary>
  6. using UnityEngine;
  7. using System.Collections;
  8. namespace ProFlares{
  9. public class Zoom : MonoBehaviour {
  10. Transform thisTrans;
  11. public float current;
  12. public float prev;
  13. void Start () {
  14. thisTrans = transform;
  15. }
  16. public float pos = 0;
  17. public float dif;
  18. public float offset;
  19. void Update () {
  20. prev = current;
  21. current = Input.GetAxis("Mouse ScrollWheel");
  22. if(Input.GetKey(KeyCode.UpArrow))
  23. current = 0.1f;
  24. if(Input.GetKey(KeyCode.DownArrow))
  25. current = -0.1f;
  26. dif = (prev-current)*-0.3f;
  27. pos = Mathf.Clamp(pos + dif,-1f,1f);
  28. Vector3 newPos = thisTrans.localPosition;
  29. newPos.z = Mathf.Clamp(thisTrans.localPosition.z+current,-2f,3f);
  30. thisTrans.localPosition = newPos;
  31. }
  32. }
  33. }