Object 회전시키기 - Touch Drag
Unity3D 2014/01/17 10:12
Object에 적용전에 Collider가 있어야 한다는걸 잊지마세요. (없다면 추가 ^^)
public class HomeRotate : MonoBehaviour {
public float rotationSpeed = 10.0f;
public float lerpSpeed = 1.0f;
private Vector3 speed = new Vector3();
private Vector3 avgSpeed = new Vector3();
private bool dragging = false;
void OnMouseDown() {
dragging = true;
}
void Update() {
if (Input.GetMouseButton(0) && dragging) {
speed = new Vector3(-Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"), 0);
avgSpeed = Vector3.Lerp (avgSpeed, speed, Time.deltaTime * 2);
}
else {
if (dragging) {
speed = avgSpeed;
dragging = false;
}
float i = Time.deltaTime * lerpSpeed;
speed = Vector3.Lerp(speed, Vector3.zero, i);
}
transform.Rotate (Camera.main.transform.up * speed.x * rotationSpeed, Space.World);
transform.Rotate (Camera.main.transform.right * speed.y * rotationSpeed, Space.World);
}