z376730842 发表于 2013-6-9 17:11

移动脚本

private var allowedGo:boolean;
private var speed1Up:boolean;
private var speed1Down:boolean;
private var speed2Up:boolean;
private var speed2Down:boolean;
private var speed1:float=0;
private var speed2:float=0;
var rotatespeed:float=10;
var maxSpeed:float=30;
function Start()
{
allowedGo=true;

}
function OnCollisionEnter(hit:Collision){
if(hit.gameObject.tag=="Terrain"){
allowedGo=true;
}
}
function OnCollisionExit(hit:Collision){
if(hit.gameObject.tag=="Terrain"){
allowedGo=false;
}
}
function Update () {
if(speed1Up==true){
if(speed1<maxSpeed){
speed1=speed1+0.5;
}
}
if(speed2Up==true){
if(speed2<maxSpeed){
speed2=speed2+0.5;
}

}
if(speed1Down==true){
if(speed1>0){
speed1=speed1-0.5;
}

}
if(speed2Down==true){
if(speed2>0){
speed2=speed2-0.5;
}
}
if(allowedGo==true){
if(Input.GetKey(KeyCode.W)){
speed1Up=true;
speed2Down=true;
speed1Down=false;
speed2Up=false;
this.transform.Translate(Vector3.forward*Time.deltaTime*(speed1-speed2));
}
else if(Input.GetKey(KeyCode.S)){
speed2Up=true;
speed1Down=true;
speed2Down=false;
speed1Up=false;
this.transform.Translate(Vector3.forward*Time.deltaTime*(speed1-speed2));
}
else
{
speed1Down=true;
speed2Down=true;
speed1Up=false;
speed2Up=false;
this.transform.Translate(Vector3.forward*Time.deltaTime*(speed1-speed2));
}
if(Input.GetKey(KeyCode.D)){
if(speed2Up==true){
this.transform.Rotate(Vector3.up*Time.deltaTime*-rotatespeed);
}
else
{
this.transform.Rotate(Vector3.up*Time.deltaTime*rotatespeed);
}
}
else if(Input.GetKey(KeyCode.A)){
if(speed2Up==true){
this.transform.Rotate(Vector3.up*Time.deltaTime*rotatespeed);
}
else
{
this.transform.Rotate(Vector3.up*Time.deltaTime*-rotatespeed);
}
}

}
else
{
speed1Down=true;
speed2Down=true;
speed1Up=false;
speed2Up=false;
this.transform.Translate(Vector3.forward*Time.deltaTime*(speed1-speed2));

}
}

Teddy 发表于 2013-11-15 20:12


我很懒,只想回复看看,另感谢楼主分享{:soso__16915934313317769624_2:}

aaabbbsss12345 发表于 2014-4-26 10:10

好 好 好 学习学习

mbb 发表于 2016-10-28 23:49


不错 不错 不错

mbb 发表于 2016-10-29 14:44


不错 不错 不错

逆耳旋律 发表于 2017-2-20 21:56

很不错

逆耳旋律 发表于 2017-2-20 22:24

楼主是超人

349061667 发表于 2017-2-20 22:31

好帖就是要顶

路在脚下 发表于 2017-2-20 22:02

难得一见的好帖

酷克数字 发表于 2017-2-20 22:40

说的非常好
页: [1]
查看完整版本: 移动脚本