Hello,
Guys i created this script but don’t know how to make the rotation work on with 2 finger touch.
It only works with 1 finger touch. Need to make it work with 2 finger touch.Please help me to solve this problem.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Rotate: MonoBehaviour {
public GameObject Obj = null;
public float minY = -45.0f;
public float maxY = 45.0f;
public float sensX = 20.0f;
public float sensY = 20.0f;
float rotationY = 0.0f;
float rotationX = 0.0f;
private float rotationRate = 0.8f;
void Update () {
foreach (Touch touch in Input.touches) {
Debug.Log("Touching at: " + touch.position);
if (touch.phase == TouchPhase.Began) {
Debug.Log("Touch phase began at: " + touch.position);
} else if (touch.phase == TouchPhase.Moved) {
Debug.Log("Touch phase Moved");
Obj.transform.Rotate (touch.deltaPosition.y * rotationRate,
-touch.deltaPosition.x * rotationRate, 0, Space.World);
} else if (touch.phase == TouchPhase.Ended) {
Debug.Log("Touch phase Ended");
}
}
}
}
Hello JoeStrout thanks for the reply. The thing is i have translate script that works with one finger and two finger . Same to rotate script too. So whenever i built this into mobile phone i have problem. I just want to make rotate object with 1 finger and translate object with 2 finger thats all. Please help me out JoeStrout
//This is the rotation script works with 1 touch and 2 touch
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class NewBehaviourScript : MonoBehaviour {
public GameObject Obj = null;
public float minY = -45.0f;
public float maxY = 45.0f;
public float sensX = 20.0f;
public float sensY = 20.0f;
float rotationY = 0.0f;
float rotationX = 0.0f;
private float rotationRate = 0.8f;
void Update () {
// get the user touch inpun
foreach (Touch touch in Input.touches) {
Debug.Log("Touching at: " + touch.position);
if (touch.phase == TouchPhase.Began) {
Debug.Log("Touch phase began at: " + touch.position);
} else if (touch.phase == TouchPhase.Moved) {
Debug.Log("Touch phase Moved");
Obj.transform.Rotate (touch.deltaPosition.y * rotationRate,
-touch.deltaPosition.x * rotationRate, 0, Space.World);
} else if (touch.phase == TouchPhase.Ended) {
Debug.Log("Touch phase Ended");
}
}
}
}
//This is the translate script. It works with 1 touch and 2 touches also same to the rotation.
using UnityEngine;
namespace Lean.Touch
{
// This script allows you to transform the current GameObject with smoothing
public class LeanTranslateSmooth : MonoBehaviour
{
[Tooltip("Does translation require an object to be selected?")]
public LeanSelectable RequiredSelectable;
public float Sharpness = 15.0f;
// The position we still need to add
private Vector3 remainingDelta;
protected virtual void Update()
{
var screenPositionDelta = LeanTouch.DragDelta;
if (RequiredSelectable != null)
{
if (RequiredSelectable.IsSelected == false)
{
return;
}
if (RequiredSelectable.Finger != null)
{
screenPositionDelta = RequiredSelectable.Finger.DeltaScreenPosition;
}
}
Translate(screenPositionDelta);
}
protected virtual void LateUpdate()
{
// The framerate independent damping factor
var factor = Mathf.Exp(-Sharpness * Time.deltaTime);
// Dampen remainingDelta
var newDelta = remainingDelta * factor;
// Shift this transform by the change in delta
transform.position += remainingDelta - newDelta;
// Update remainingDelta with the dampened value
remainingDelta = newDelta;
}
private void Translate(Vector2 screenPositionDelta)
{
// Store old position
var oldPosition = transform.position;
// Screen position of the transform
var screenPosition = Camera.main.WorldToScreenPoint(oldPosition);
// Add the deltaPosition
screenPosition += (Vector3)screenPositionDelta;
// Convert back to world space
var newPosition = Camera.main.ScreenToWorldPoint(screenPosition);
var delPosition = newPosition - oldPosition;
// Add to delta
remainingDelta += delPosition;
}
}
}
Here is the Update method from my game where I have a single touch orbit, but a two-finger touch zoom. I had originally tried two-finger orbit, but my playtesters (wife and brother) found it unintuitive.