---
title: "Unity 3D之移动游戏对象模型"
author: "convolute"
date: "2013-05-02T14:55:32Z"
tags: []
categories: ["移动开发"]
slug: "unity-3d"
draft: false
lastmod: "2013-05-02T14:55:32Z"
id: 1858717
url: "https://convolute.iteye.com/blog/1858717"
---

Unity3D中使用脚本移动游戏对象模型，就需要改变游戏对象的Position坐标，代码如下：

```
function Update(){

//移动游戏对象模型

transform.Translate(Vector3.forward * Time.deltaTime);

}
```

 

 

注意：

1.Update()方法为系统自动调用，系统在每一帧都会调用该方法。

2.transform.Translate()方法用于设置游戏对象平移的方向，该方向中的参数为移动的方向，其中Vector3.forward表示移动的方向为前方，Time.deltaTime表示Update()方法上一帧持续的时间，它俩的乘积就是沿着前方模型一次移动的距离。

视图如下：

![](http://dl.iteye.com/upload/attachment/0083/9373/b1451acb-c70c-3c15-b6d2-b786261ce049.png)  
 

上述代码的作用是：运行游戏后，立方体游戏对象将缓慢向前移动。

另外，将上述代码写好后，将MoveModel.js脚本绑定到一个立方体游戏对象中。

&lt;!--EndFragment--&gt;

 

&lt;!--EndFragment--&gt;