Beispiel #1
0
 // Update is called once per frame
 void Update()
 {
     turnDegree = (0.0015f * Mathf.Pow(turnDegreeInput, 2));
     if (active)
     {
         transform.Translate(0, 0, velocity);
         if (!moving)
         {
             if (fb.GetKeysDown(4) && (curLanePos > -1 * maxLanePos))   // Left : Key 4
             {
                 curLanePos--;
                 moving   = true;
                 left     = true;
                 velocity = velocityExp;
                 marker.updateMarker(velocityExp);
                 InvokeRepeating("newTurnLeft", 0, laneChangeSpeed);
             }
             if (fb.GetKeysDown(3) && (curLanePos < maxLanePos))   // Right : Key 3
             {
                 curLanePos++;
                 moving   = true;
                 right    = true;
                 velocity = velocityExp;
                 marker.updateMarker(velocityExp);
                 InvokeRepeating("newTurnRight", 0, laneChangeSpeed);
             }
             if (velocity != 0)
             {
                 if (fb.GetKeysDown(1))   // Up : Key 1
                 {
                     if (velocityExp < maxSpeed)
                     {
                         velocityExp += 0.05f;
                         velocity     = velocityExp;
                         marker.updateMarker(velocityExp);
                     }
                 }
                 if (fb.GetKeysDown(2))   // Down: Key 2
                 {
                     if (velocityExp > minSpeed)
                     {
                         velocityExp -= 0.05f;
                         velocity     = velocityExp;
                         marker.updateMarker(velocityExp);
                     }
                 }
             }
             if (velocity == 0 && fb.GetKeysDown(1))   // Up: Key 1
             {
                 velocity = velocityExp;
                 marker.updateMarker(velocityExp);
             }
         }
     }
 }
Beispiel #2
0
        // Use this for initialization
        void Start()
        {
            GameObject historyObject = GameObject.Find("History");

            history = historyObject.GetComponent <History>();
            placeCar(history.levelName);

            maxSpeed        = history.getCarMaxSpeed();
            minSpeed        = history.getCarMinSpeed();
            laneChangeSpeed = history.getLaneChangeSpeed();

            fb = GameObject.FindObjectOfType <FitBoardHandler>();

            curLanePos = 0;
            child      = GameObject.Find("Car").GetComponent <Transform>();
            marker     = GameObject.Find("Marker").GetComponent <SpeedometerMarker>();
            velocity   = velocityExp;
            marker.updateMarker(velocityExp);
            moving          = false;
            left            = false;
            right           = false;
            hittingSide     = false;
            laneChangeHelp  = false;
            laneChangeHelp2 = false;
            noHits          = true;
            turnDegreeInput = 1;
            turnDegree      = (0.0015f * Mathf.Pow(turnDegreeInput, 2));
            relPos          = 0;
            active          = false;
        }
Beispiel #3
0
 void OnTriggerEnter(Collider other)
 {
     if (!other.name.Contains("Barrier") && !other.name.Contains("Finish"))
     {
         mover.velocity = 0;
         marker.updateMarker(0);
         failure = true;
         if (!mover.moving)
         {
             Debug.Log("head on");
             mover.transform.position = new Vector3(mover.transform.position.x, mover.transform.position.y, mover.transform.position.z - 15);
         }
         else if (mover.left)
         {
             Debug.Log("While moving left");
             float laneval = Mathf.Floor(mover.transform.position.x / 25) * 25;
             mover.transform.position = new Vector3(laneval, mover.transform.position.y, mover.transform.position.z - 15);
             mover.ResetParams();
         }
         else
         {
             Debug.Log("While moving right");
             float laneval = Mathf.Floor(mover.transform.position.x / 25) * 25 + 25;
             mover.transform.position = new Vector3(laneval, mover.transform.position.y, mover.transform.position.z - 15);
             mover.ResetParams();
         }
         mover.noHits = false;
         collisions++;
         collisionSound.Play();
     }
     else
     {
         if (!failure && other.name.Contains("Barrier") && !other.name.Contains("Finish"))
         {
             scoreKeeper.passObstacle();
         }
         else if (!other.name.Contains("Terrain"))
         {
             failure = false;
         }
     }
 }