Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.EventSystems;
- public enum RotateType
- {
- Automatico,
- Manual
- };
- public class RotateTransformInUI : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
- {
- public bool isPress;
- public float Sensibilidad;
- public Transform ObjectToRotate;
- public static RotateTransformInUI sh;
- public float RotateForceXAutomatic, RotateForceXManual;
- public RotateType TipoDeRotacion;
- private void Awake()
- {
- if (sh == null)
- {
- sh = this;
- }
- }
- private void Update()
- {
- if (isPress && ObjectToRotate != null)
- {
- switch (TipoDeRotacion)
- {
- case RotateType.Automatico:
- {
- RotateForceXAutomatic -= Input.GetAxis("Mouse X") * Time.deltaTime * Sensibilidad * 1;
- RotateForceXAutomatic = Mathf.Clamp (RotateForceXAutomatic, -1, 1);
- ObjectToRotate.Rotate (0f, RotateForceXAutomatic, 0f);
- break;
- }
- case RotateType.Manual:
- {
- if (TipoDeRotacion == RotateType.Manual)
- {
- RotateForceXManual -= Input.GetAxis("Mouse X") * Time.deltaTime * Sensibilidad * 40;
- ObjectToRotate.rotation = Quaternion.Euler(0f, RotateForceXManual, 0f);
- }
- break;
- }
- }
- }
- }
- public void OnPointerDown (PointerEventData data)
- {
- isPress = true;
- }
- public void OnPointerUp (PointerEventData data)
- {
- isPress = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement