码迷,mamicode.com
首页 > 移动开发 > 详细

Unity3D 控制物体移动、旋转、缩放

时间:2014-11-04 21:10:58      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:unity3d   移动   旋转   缩放   

Transform基本移动函数:

transform.Translate(Vector3.forward *TranslateSpeed);
transform.Translate(xSpeed,0,zSpeed);
transform.position = Vector3(xPostion,0,zPostion);

1.输入指定按键:

if(Input.GetKey ("up"))
  print("Up!");
if(Input.GetKey(KeyCode.W);)
  print("W!");

2.鼠标控制

//按下鼠标左键(0对应左键 , 1对应右键 , 2对应中键) 
if(Input.GetMouseButton(0))
  print("Mouse Down!");
Input.GetAxis("Mouse X");//鼠标横向增量(横向移动) 
Input.GetAxis("Mouse Y");//鼠标纵向增量(纵向移动)

3.获取轴:

//水平轴/垂直轴 (控制器和键盘输入时此值范围在-1到1之间)
Input.GetAxis("Horizontal");//横向 
Input.GetAxis ("Vertical");//纵向

物体旋转

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

物体缩放:

    transform.localScale += new Vector3(x, 0, z);  

Unity3D 控制物体移动、旋转、缩放

标签:unity3d   移动   旋转   缩放   

原文地址:http://blog.csdn.net/a350203223/article/details/40791229

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!