Hai,
I am new to unity.I am developing a project on rotating the Game-Object on its fixed position while swiping.Actually i can rotate the object with “transform.rotateAround” as well as “transform.Rotate” but my problem is my game object its moving from its place while rotating which i dont want.I want it to be stable.I cant figure out the problem.Can any help me with this?
I have attached my program below,
#pragma strict
var cube:Transform;
function Start () {
cube = GameObject.Find(“cube”).transform;
}
function Update () {
if(Input.touchCount >= 1) {
if (Input.touchCount == 2 && Input.GetTouch(0).phase == TouchPhase.Moved && Input.GetTouch(1).phase == TouchPhase.Moved) {
var touch1:Touch = Input.GetTouch(0);
var touch2:Touch = Input.GetTouch(1);
if(touch1.deltaPosition.x > 0 && touch2.deltaPosition.x > 0) {
Rotate3DObject(touch1, touch2);
} else if(touch1.deltaPosition.x < 0 && touch2.deltaPosition.x < 0) {
Rotate3DObject1(touch1, touch2);
}
}
}
}
function Rotate3DObject(touch1:Touch, touch2:Touch) {
cube.RotateAround(cube.position,Vector3.up,-touch1.deltaPosition.x);
}