CUI_GunMovement.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using UnityEngine;
  2. using System.Collections;
  3. namespace CurvedUI
  4. {
  5. /// <summary>
  6. /// A simple script to make the pointer follow mouse movement and pass the control ray to canvsa
  7. /// </summary>
  8. public class CUI_GunMovement : MonoBehaviour
  9. {
  10. #pragma warning disable 0649
  11. [SerializeField]
  12. CurvedUISettings mySettings;
  13. [SerializeField]
  14. Transform pivot;
  15. [SerializeField]
  16. float sensitivity = 0.1f;
  17. Vector3 lastMouse;
  18. #pragma warning restore 0649
  19. // Use this for initialization
  20. void Start()
  21. {
  22. lastMouse = Input.mousePosition;
  23. }
  24. // Update is called once per frame
  25. void Update()
  26. {
  27. Vector3 mouseDelta = Input.mousePosition - lastMouse;
  28. lastMouse = Input.mousePosition;
  29. pivot.localEulerAngles += new Vector3(-mouseDelta.y, mouseDelta.x, 0) * sensitivity;
  30. //pass ray to canvas
  31. Ray myRay = new Ray(this.transform.position, this.transform.forward);
  32. CurvedUIInputModule.CustomControllerRay = myRay;
  33. CurvedUIInputModule.CustomControllerButtonState = Input.GetButton("Fire1");
  34. }
  35. }
  36. }