using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WS_RotaTest : MonoBehaviour {
private bool roate;
private float RoatedSpeed = 1000.0F;
Vector3 v3;
void Start()
{
roate = false;
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButton(0))
{
if (roate)
{
Vector3 offset = v3 - Input.mousePosition;
print(offset);
if (offset.y > 0)
{
gameObject.transform.Rotate(new Vector3(1, 0, 0));
}
else if (offset.y == 0)
{
}
else
{
gameObject.transform.Rotate(new Vector3(-1, 0, 0));
}
}
//localEulerAngles是右边的vector3值
this.transform.localEulerAngles = new Vector3(value, 0, 0);
//float y = 0;
//y = Input.GetAxis("Mouse Y") * RoatedSpeed * Time.deltaTime;
//if (roate)
//{
// print(y.ToString());
// gameObject.transform.Rotate(new Vector3(y, 0, 0));
//}
}
}
void OnMouseDown()
{
v3 = Input.mousePosition;
roate = true;
Debug.Log("collider");
}
void OnMouseUp()
{
roate = false;
Debug.Log("Out of collider");
}
}
挂再需要旋转的物体上面。