移动脚本
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));
}
}
我很懒,只想回复看看,另感谢楼主分享{:soso__16915934313317769624_2:} 好 好 好 学习学习
不错 不错 不错
不错 不错 不错 很不错 楼主是超人 好帖就是要顶 难得一见的好帖 说的非常好
页:
[1]