|
using UnityEngine;
using System.Collections;
public class charactorCtr : MonoBehaviour {
private Transform myTransform;
public float roadWidth = 5f; //跑道的宽度
public int speed=2;
void Start () {
myTransform = this.transform;
}
void Update () {
myTransform.Translate (0,0,speed*Time.deltaTime);
if(myTransform.position.x<roadWidth){
if(Input.GetKeyUp(KeyCode.D)){
myTransform.position=new Vector3(myTransform.position.x+roadWidth,myTransform.position.y,myTransform.position.z);
}
}
if(myTransform.position.x>(0f-roadWidth)){
if(Input.GetKeyUp(KeyCode.A)){
myTransform.position=new Vector3(myTransform.position.x-roadWidth,myTransform.position.y,myTransform.position.z);
}
}
}
} |
|