using UnityEngine;
using System.Collections;
public class ModelRotation : MonoBehaviour {
public float speed = 20.0f;
private float flag;
private float flag_y;
private bool bRotate;
// Use this for initialization
void Start () {
bRotate = false;
}
// Update is called once per frame
void Update () {
flag = Input.GetAxis("Mouse X");
flag_y = Input.GetAxis("Mouse Y");
if(flag > 0 && flag_y == 0)
{
if (Input.GetKey("left")){
this.transform.Rotate(Vector3.up*Time.deltaTime*-speed);
}
if (Input.GetKey("right")){
this.transform.Rotate(Vector3.up*Time.deltaTime*speed);
}
}
}
void OnGUI(){
if(Event.current.type == EventType.MouseDrag){
if(bRotate && gameObject.rigidbody.angularVelocity.x == 0){
//transform.Rotate(new Vector3(0, -Input.GetAxis("Mouse X"), 0)*speed);
transform.Rotate(new Vector3(0,-Input.GetAxis("Mouse X"),0)*speed);
}
else if(bRotate && gameObject.rigidbody.angularVelocity.z == 0)
{
transform.Rotate(new Vector3(0, 0, -Input.GetAxis("Mouse Y"))*speed);
Debug.Log("rotate v");
}
}
}
void OnMouseEnter(){
clickObj scriptObj = (clickObj)gameObject.GetComponent<clickObj>();
bool bFlag = scriptObj.bDrag;
if(!bFlag)
bRotate = true;
}
void OnMouseExit(){
bRotate = false;
}
}
using UnityEngine;
using System.Collections;
public class ModelRotation : MonoBehaviour {
public float speed = 20.0f;
private float flag;
private float flag_y;
private bool bRotate;
// Use this for initialization
void Start () {
bRotate = false;
}
// Update is called once per frame
void Update () {
flag = Input.GetAxis("Mouse X");
flag_y = Input.GetAxis("Mouse Y");
if(flag > 0 && flag_y == 0)
{
if (Input.GetKey("left")){
this.transform.Rotate(Vector3.up*Time.deltaTime*-speed);
}
if (Input.GetKey("right")){
this.transform.Rotate(Vector3.up*Time.deltaTime*speed);
}
}
}
void OnGUI(){
if(Event.current.type == EventType.MouseDrag){
if(bRotate && gameObject.rigidbody.angularVelocity.x == 0){
//transform.Rotate(new Vector3(0, -Input.GetAxis("Mouse X"), 0)*speed);
transform.Rotate(new Vector3(0,-Input.GetAxis("Mouse X"),0)*speed);
}
else if(bRotate && gameObject.rigidbody.angularVelocity.z == 0)
{
transform.Rotate(new Vector3(0, 0, -Input.GetAxis("Mouse Y"))*speed);
Debug.Log("rotate v");
}
}
}
void OnMouseEnter(){
clickObj scriptObj = (clickObj)gameObject.GetComponent<clickObj>();
bool bFlag = scriptObj.bDrag;
if(!bFlag)
bRotate = true;
}
void OnMouseExit(){
bRotate = false;
}
}