using UnityEngine;
using System.Collections;
public class RoatMove : MonoBehaviour {
public GameObject o;
public GameObject r;
float a;
float aa;
bool b;
bool bb;
Vector3 weizhi;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0))
{
//按下鼠标左键 将鼠标位置赋值给weizhi 方便后面进行对比
weizhi = Input.mousePosition;
}
if (Input.GetMouseButton(0))
{
if (weizhi.x>Input.mousePosition.x)//如果位置的x轴大于现在鼠标的x轴,说明鼠标再往左移动
{
a = -1f;
b = true;
weizhi = Input.mousePosition;//将现在鼠标的·1值赋值给weizhi
}
else if (weizhi.x<Input.mousePosition.x)
{
a = 1f;
b = true;
weizhi = Input.mousePosition;
}
else if (weizhi.x==Input.mousePosition.x)
{
a = 0;
}
}
if (Input.GetMouseButtonUp(0))//如果抬起鼠标 旋转关闭
{
a = 0;
b = false;
}
if (b)
{
//要动的物体r 中心点 要移动哪个轴就不为0 移动的速度a
r.transform.RotateAround(o.transform.position, new Vector3(0, 1, 0), a);
}
if (Input.GetMouseButtonDown(2))
{
weizhi = Input.mousePosition;
}
if (Input.GetMouseButton(2))
{
if (weizhi.y>Input.mousePosition.y)
{
aa = -1;
bb = true;
weizhi = Input.mousePosition;
}
else if (weizhi.y<Input.mousePosition.y)
{
aa = 1;
bb = true;
weizhi = Input.mousePosition;
}
else if (weizhi.y==Input.mousePosition.y)
{
aa = 0;
}
}
if (bb)
{
r.transform.RotateAround(o.transform.position, new Vector3(1, 0, 0), aa);
}
if (Input.GetMouseButtonUp(2))
{
aa = 0;
bb = false;
}
}
}