unity3d控制物体移动(触控、鼠标、键盘)

float x;

float y;

if (Input.touchCount > 0) { //触控

    x = Input.GetTouch (0).deltaPosition.x * 0.01f;

    y = Input.GetTouch (0).deltaPosition.y * 0.01f;

} else if (Input.GetMouseButton (0)) { //鼠标

    x = Input.GetAxis ("Mouse X")*0.1f;

    y = Input.GetAxis ("Mouse Y")*0.1f;

}else { //键盘

    x = Input.GetAxis ("Horizontal")*0.1f;

    y = Input.GetAxis ("Vertical")*0.1f;

}

transform.Translate (new Vector3 (x, 0, y));