Unity3d移動程式碼(指令碼)向前向後以及轉彎,速度轉向控制
阿新 • • 發佈:2018-12-26
#pragma strict
function Start () {
}
var MoveSpeed=5;
var RotateSpeed=20;
function Update () {
if(this.transform.up.y>0 && this.transform.up.y<=10)
if(Input.GetKey(KeyCode.W))
{
print("Moving W");
if(MoveSpeed<=30){
MoveSpeed = MoveSpeed + 10*Time.deltaTime;
}
this.transform.Translate(Vector3.forward*Time.deltaTime*MoveSpeed);
if(Input.GetKey(KeyCode.A))
{
this.transform.Rotate(Vector3.up*Time.deltaTime*-RotateSpeed);
}
else if(Input.GetKey(KeyCode.D))
{
this.transform.Rotate(Vector3.up*Time.deltaTime*RotateSpeed);
}
}
else if(Input.GetKey(KeyCode.S))
{
print("MOving S");
MoveSpeed = 5;
this.transform.Translate(Vector3.forward*Time.deltaTime*-MoveSpeed);
if(Input.GetKey(KeyCode.A))
{
this.transform.Rotate(Vector3.up*Time.deltaTime*-RotateSpeed);
}
else if(Input.GetKey(KeyCode.D))
{
this.transform.Rotate(Vector3.up*Time.deltaTime*RotateSpeed);
}
}
else if(Input.GetKey(KeyCode.A))
{
MoveSpeed = 5;
this.transform.Translate(Vector3.forward*Time.deltaTime*0.1*MoveSpeed);
this.transform.Rotate(Vector3.up*Time.deltaTime*-RotateSpeed);
}
else if(Input.GetKey(KeyCode.D))
{
MoveSpeed = 5;
this.transform.Translate(Vector3.forward*Time.deltaTime*0.1*MoveSpeed);
this.transform.Rotate(Vector3.up*Time.deltaTime*RotateSpeed);
}
}
function Start () {
}
var MoveSpeed=5;
var RotateSpeed=20;
function Update () {
if(this.transform.up.y>0 && this.transform.up.y<=10)
if(Input.GetKey(KeyCode.W))
{
print("Moving W");
if(MoveSpeed<=30){
MoveSpeed = MoveSpeed + 10*Time.deltaTime;
}
this.transform.Translate(Vector3.forward*Time.deltaTime*MoveSpeed);
if(Input.GetKey(KeyCode.A))
{
this.transform.Rotate(Vector3.up*Time.deltaTime*-RotateSpeed);
}
else if(Input.GetKey(KeyCode.D))
{
this.transform.Rotate(Vector3.up*Time.deltaTime*RotateSpeed);
}
}
else if(Input.GetKey(KeyCode.S))
{
print("MOving S");
MoveSpeed = 5;
this.transform.Translate(Vector3.forward*Time.deltaTime*-MoveSpeed);
if(Input.GetKey(KeyCode.A))
{
this.transform.Rotate(Vector3.up*Time.deltaTime*-RotateSpeed);
}
else if(Input.GetKey(KeyCode.D))
{
this.transform.Rotate(Vector3.up*Time.deltaTime*RotateSpeed);
}
}
else if(Input.GetKey(KeyCode.A))
{
MoveSpeed = 5;
this.transform.Translate(Vector3.forward*Time.deltaTime*0.1*MoveSpeed);
this.transform.Rotate(Vector3.up*Time.deltaTime*-RotateSpeed);
}
else if(Input.GetKey(KeyCode.D))
{
MoveSpeed = 5;
this.transform.Translate(Vector3.forward*Time.deltaTime*0.1*MoveSpeed);
this.transform.Rotate(Vector3.up*Time.deltaTime*RotateSpeed);
}
}