I am using the new canvas system in conjunction with minor touch screen code to rotate a dial. currently the dial moves positive or negative depending on the way the user moves their mouse/finger on screen.
The client I am building this for would like to have it rotate as the user rotates their finger around the dial. My code currently only checks if they are moving up and down OR left and right. What would be simplest way to achieve their desired movement?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class SpinnerScript : MonoBehaviour {
public Vector2 mouseDownPoint;
public Vector2 mouseDragPoint;
public float yDif;
public bool dragging;
public float rotSpeed;
// Update is called once per fram
void Update () {
if (Input.GetMouseButtonDown (0)) {
//print("thisCollider");
//returnBtn.GetComponent<Animator> ().SetTrigger ("Show");
dragging = true;
mouseDownPoint = new Vector2( Input.mousePosition.x / Screen.width , Input.mousePosition.y / Screen.height ) ;
}else{
//Debug.Log("check your rays!!!");
}
if (dragging) {
if(Input.GetMouseButton(0)){
mouseDragPoint = new Vector2( Input.mousePosition.x / Screen.width , Input.mousePosition.y / Screen.height ) ;
}
SetAnimSpeed();
if (Input.GetMouseButtonUp (0)) {
dragging = false;
}
}
}
void SetAnimSpeed(){
//print ("setenter");
yDif = 0 + ( mouseDragPoint.y - mouseDownPoint.y);
transform.Rotate (Vector3.forward * yDif * rotSpeed);
}
}