Hi
I am working with vuforia sdk in Unity…I have an AR Object.I need to rotate the object 360 Degrees(rotate all sides) by touch .How to rotate using C# script??
I used this script for rotation…But i cannot rotate 360 degree?? help me…
using UnityEngine;
using System.Collections;
public class Rotate : MonoBehaviour {
public Bounds bounds;
public float speed = 1.0F;
// Use this for initialization
void Start () {
var collider = gameObject.GetComponent<BoxCollider> ();
if (collider == null) {
collider = gameObject.AddComponent<BoxCollider>();
Debug.Log("No Collider is Detected");
}
bounds = collider.bounds;
}
// Update is called once per frame
void Update () {
if(Input.GetMouseButton(0)){
if(bounds.size.magnitude > 0){
var dtx = Input.GetAxis("Mouse X")*speed;
var dty = Input.GetAxis("Mouse Y")*speed;
var pivot = bounds.center;
transform.RotateAround(pivot,Vector3.right,dtx);
transform.RotateAround(pivot,Vector3.forward,dty);
}
}
}
}
Register and listen for the panning gesture and then rotate your model over y, or you could orbit the camera like I did in the following code. You could modify it to rotate your object instead.
// main
public Transform cameraTransform;
public Transform cameraPivot;
// orbit settings
public Vector2 orbitSpeed = Vector2.one;
public bool orbitLockPoles = true;
protected TKPanRecognizer panRecognizer;
protected Vector2 orbitMultiplier = new Vector2(0.3f, 0.3f);
void Start() {
panRecognizer = new TKPanRecognizer();
panRecognizer.gestureRecognizedEvent += orbitGestureRecognizedHandler;
TouchKit.addGestureRecognizer(panRecognizer);
}
private void orbitGestureRecognizedHandler(TKPanRecognizer recognizer) {
float angle = recognizer.deltaTranslation.x * orbitMultiplier.x * orbitSpeed.x;
cameraTransform.RotateAround(cameraPivot.position, Vector3.up, angle);
angle = -recognizer.deltaTranslation.y * orbitMultiplier.y * orbitSpeed.y;
if (orbitLockPoles) {
float x = cameraTransform.eulerAngles.x;
if (x <= 90) angle = Mathf.Min(angle, 90 - x);
if (x >= 270) angle = Mathf.Max(angle, 270 - x);
}
cameraTransform.RotateAround(cameraPivot.position, cameraTransform.right, angle);
}