This is the script for mouse input. Can someone please tell how to convert this for Andriod Touch Input???
using UnityEngine;
using System.Collections;
public class MouseDrag : MonoBehaviour
{
public float speed = 1f;
private float baseAngle = 0.0f;
private float maxRotaion = 80f;
private Quaternion currentRotation,defaultRotation;
void Start()
{
defaultRotation = transform.rotation;
}
void OnMouseDown ()
{
var dir = Camera.main.WorldToScreenPoint (transform.position);
dir = Input.mousePosition - dir;
baseAngle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
baseAngle -= Mathf.Atan2(transform.right.y, transform.right.x) * Mathf.Rad2Deg;
}
void OnMouseDrag ()
{
// Limit platform rotation
var dir = Camera.main.WorldToScreenPoint (transform.position);
dir = Input.mousePosition - dir;
var angle = Mathf.Atan2 (dir.y, dir.x) * Mathf.Rad2Deg - baseAngle;
if (angle >= -maxRotaion && angle <= maxRotaion)
transform.rotation = Quaternion.AngleAxis (angle, Vector3.forward);
currentRotation = transform.rotation;
}
void OnMouseUp()
{
StartCoroutine (RotateObject (transform, currentRotation, defaultRotation, 3.0f));
}
IEnumerator RotateObject(Transform thisTransform, Quaternion from, Quaternion to, float time)
{
float i = 0.0f;
float rate = 1.0f / time;
while (i < 1.0f)
{
i += Time.deltaTime * rate * speed;
transform.rotation = Quaternion.Slerp(from, to, i);
yield return null;
}
}
}