private float Timer; // 纪录时间 private void Awake() { DoPlayerPath = GetComponent <DOTweenPath>(); DoCar1Path = Car1.GetComponent <DOTweenPath>(); DoCar2Path = Car2.GetComponent <DOTweenPath>(); DoCar3Path = Car3.GetComponent <DOTweenPath>(); }
// Update is called once per frame void Update() { if (IsGameOver == false) { Car1.GetComponent <Rigidbody2D> ().isKinematic = false; Car2.GetComponent <Rigidbody2D> ().isKinematic = false; //Action on left key Pressed //Action on left key Pressed if (Input.GetKeyDown("left")) { LeftButton(); } //Action on right key pressed else if (Input.GetKeyDown("right")) { RightButton(); } } else { Car1.GetComponent <Rigidbody2D> ().isKinematic = true; Car2.GetComponent <Rigidbody2D> ().isKinematic = true; } }
// Use this for initialization void Start() { Car1.GetComponent <Rigidbody>().isKinematic = false; Car2.GetComponent <Rigidbody>().isKinematic = false; }
//In CurrentPosiiton 0 represent center, -1 left and 1 right. public void LeftButton() { Debug.Log("Left button"); //If at center move to left if (Car1.GetComponent <PlayerController> ().teleporting == false && Car1CurrentPosition - 1 != Car2CurrentPosition) { if (Car1CurrentPosition == 2) { //animate movemenet to -2.1 i.e left Car1.transform.DOMoveX(-2.45f, 0.5f); //set current position to -1 i.e. left. Car1CurrentPosition = 1; //If at right move to center } else if (Car1CurrentPosition == 3) { //animate movemenet to 0 i.e center Car1.transform.DOMoveX(-1.75f, 0.5f); //set current position to 0 i.e. center. Car1CurrentPosition = 2; } else if (Car1CurrentPosition == 4) { //animate movemenet to 0 i.e center Car1.transform.DOMoveX(-1.05f, 0.5f); //set current position to 0 i.e. center. Car1CurrentPosition = 3; } else if (Car1CurrentPosition == 6) { //animate movemenet to 0 i.e center Car1.transform.DOMoveX(0.35f, 0.5f); //set current position to 0 i.e. center. Car1CurrentPosition = 5; } else if (Car1CurrentPosition == 7) { //animate movemenet to 0 i.e center Car1.transform.DOMoveX(1.05f, 0.5f); //set current position to 0 i.e. center. Car1CurrentPosition = 6; } else if (Car1CurrentPosition == 8) { //animate movemenet to 0 i.e center Car1.transform.DOMoveX(1.75f, 0.5f); //set current position to 0 i.e. center. Car1CurrentPosition = 7; } } //Second car //If at center move to left if (Car2.GetComponent <PlayerController> ().teleporting == false && Car2CurrentPosition - 1 != Car1CurrentPosition) { if (Car2CurrentPosition == 2) { //animate movemenet to -2.1 i.e left Car2.transform.DOMoveX(-2.45f, 0.5f); //set current position to -1 i.e. left. Car2CurrentPosition = 1; //If at right move to center } else if (Car2CurrentPosition == 3) { //animate movemenet to 0 i.e center Car2.transform.DOMoveX(-1.75f, 0.5f); //set current position to 0 i.e. center. Car2CurrentPosition = 2; } else if (Car2CurrentPosition == 4) { //animate movemenet to 0 i.e center Car2.transform.DOMoveX(-1.05f, 0.5f); //set current position to 0 i.e. center. Car2CurrentPosition = 3; } else if (Car2CurrentPosition == 6) { //animate movemenet to 0 i.e center Car2.transform.DOMoveX(0.35f, 0.5f); //set current position to 0 i.e. center. Car2CurrentPosition = 5; } else if (Car2CurrentPosition == 7) { //animate movemenet to 0 i.e center Car2.transform.DOMoveX(1.05f, 0.5f); //set current position to 0 i.e. center. Car2CurrentPosition = 6; } else if (Car2CurrentPosition == 8) { //animate movemenet to 0 i.e center Car2.transform.DOMoveX(1.75f, 0.5f); //set current position to 0 i.e. center. Car2CurrentPosition = 7; } } }