找回密码
 注册帐号

扫一扫,访问微社区

charactercontroller.simplemove 简单移动

2015-1-4 11:37| 发布者: 杨炎| 查看: 3045| 评论: 0|原作者: 蛮牛|来自: unity3d脚本manual

摘要: charactercontroller.simplemove 简单移动functionsimplemove(speed:vector3) : booldescription描述moves the character with speed.以一定的速度移动角色。velocity along the y-axis is ignored. speed is in met ...

charactercontroller.simplemove 简单移动

functionsimplemove(speed:vector3) : bool

description描述

moves the character with speed.

以一定的速度移动角色

velocity along the y-axis is ignored. speed is in meters/s. gravity is automatically applied. returns if the character is grounded. it is recommended that you make only one call to move or simplemove per frame.

y 轴上速度被忽略。速度以米/秒为单位。重力被自动应用。返回如果角色着地。建议你每帧只调用一次move或者simplemove。

c#

javascript

using unityengine;

using system.collections;

public class example :monobehaviour{

public float speed = 3.0f;

public float rotatespeed = 3.0f;

void update() {

charactercontroller controller = getcomponent();

transform.rotate(0, input.getaxis("horizontal") * rotatespeed, 0);

vector3 forward = transform.transformdirection(vector3.forward);

float curspeed = speed * input.getaxis("vertical");

controller.simplemove(forward * curspeed);

}

}

var speed : float = 3.0;

var rotatespeed : float = 3.0;

function update () {

var controller : charactercontroller = getcomponent(charactercontroller);

// rotate around y - axis

//围绕y轴旋转

transform.rotate(0, input.getaxis ("horizontal") * rotatespeed, 0);

// move forward / backward

//向前后移动

var forward :vector3= transform.transformdirection(vector3.forward);

var curspeed : float = speed * input.getaxis ("vertical");

controller.simplemove(forward * curspeed);

}

@script requirecomponent(charactercontroller)

文章点评