- 最后登录
- 2014-10-23
- 注册时间
- 2011-7-19
- 阅读权限
- 90
- 积分
- 81303
 
- 纳金币
- -1
- 精华
- 11
|
和2D一样,还是用到Input.acceleration;但不同的是,3D中要得把世界坐标转化成屏幕坐标,这个方法前面有提到过,就是WorldToScreenPoint,再用屏幕坐标进行计算,最后再转化成世界坐标就行。下面我们看看代码吧。
var target:Transform;
function Update(){
var screenpos=Camera.main.WorldToScreenPoint(target.position);
screenpos.y+=Input.acceleration.x*100*Time.deltaTime;
screenpos.x -=Input.acceleration.y*100*Time.deltaTime;
target.position=Camera.main.ScreenToWorldPoint(screenpos);
}
function OnGUI(){
GUI.Label(Rect(Screen.width/2,Screen.height/2,100,100),""+Input.acceleration);
}
这里的screenpos.y+=Input.acceleration.x*100*Time.deltaTime; screenpos.x -=Input.acceleration.y*100*Time.deltaTime;这些
x,y到时候根据你的效果来更改吧。
比较实用的开发小知识,转过来大家学习下:http://blog.csdn.net/dlnuchunge/article/details/7380829 |
|