CharacterController.SimpleMove 简单移动
function SimpleMove (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。
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public float speed = 3.0F;
public float rotateSpeed = 3.0F;
void Update() {
CharacterController controller = GetComponent<CharacterController>();
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)
最后修改:2010年12月14日 Tuesday 15:00