unity 用鼠标控制相机绕着物体旋转脚本
2016-05-11 14:08
881 查看
using UnityEngine;
using System.Collections;
public class RotateObj : MonoBehaviour {
public GameObject cube;
float horizontalSPeed =2.0f;
float verticalSpeed = 2f ;
float x,y;
float speed=30f;
float distance=5;
Vector3 center;
// Use this for initialization
void Start () {
center = cube.transform.position;
}
// Update is called once per frame
void Update () {
// float h = horizontalSPeed * Input.GetAxis ("Mouse X");
// float v = verticalSpeed * Input.GetAxis ("Mouse Y");
// transform.Rotate (v,h,0);
if (Input.GetMouseButton(1))
{
x += Input.GetAxis("Mouse X") * speed * Time.deltaTime;
y += Input.GetAxis("Mouse Y") * speed * Time.deltaTime;
Debug.Log ("x: "+x);
Quaternion q = Quaternion.Euler(y, x, 0);
Vector3 direction = q * Vector3.forward;
this.transform.position = center - direction * distance;
//this.transform.LookAt(center);
}
}
}
using System.Collections;
public class RotateObj : MonoBehaviour {
public GameObject cube;
float horizontalSPeed =2.0f;
float verticalSpeed = 2f ;
float x,y;
float speed=30f;
float distance=5;
Vector3 center;
// Use this for initialization
void Start () {
center = cube.transform.position;
}
// Update is called once per frame
void Update () {
// float h = horizontalSPeed * Input.GetAxis ("Mouse X");
// float v = verticalSpeed * Input.GetAxis ("Mouse Y");
// transform.Rotate (v,h,0);
if (Input.GetMouseButton(1))
{
x += Input.GetAxis("Mouse X") * speed * Time.deltaTime;
y += Input.GetAxis("Mouse Y") * speed * Time.deltaTime;
Debug.Log ("x: "+x);
Quaternion q = Quaternion.Euler(y, x, 0);
Vector3 direction = q * Vector3.forward;
this.transform.position = center - direction * distance;
//this.transform.LookAt(center);
}
}
}
相关文章推荐
- Unity中的Path对应各平台中的Path
- unity 在移动平台中,文件操作路径详解
- 浅谈unity3d中使用MVC框架模式
- Android Studio 2.1 和 Unity3D 5.3.4 交互(二)
- Unity3D中uGUI事件系统简述及使用方法总结
- Unity3.X 笔记01
- 旋转角色
- Unity3d Realtime Dynamic Clouds Rendering
- Unity Shaders and Effects Cookbook (7-1) 在Surface Shader 中 访问 顶点颜色
- unity 的内存管理
- unity+Cardboard SDK VR开发Cardboard Unity SDK讲解
- unity+Cardboard SDK VR开发教程
- 一个unity 牛的博客网址
- Unity打包Android备忘
- <Unity-UGUI>使用Mask, 正确的裁减非默认材质UI对象
- Unity Shader学习1——简述
- Unity 关于unity中的update、Lateupdate和FixedUpdate。
- Unity Raycast 光线投射
- Unity3D射线检测控制转向
- WMware 10 Ubuntu 12.04 进入Unity模式