コード例 #1
0
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.R))
        {
            SceneManager.LoadScene(0);
        }

        if (Input.GetKeyDown(KeyCode.W))
        {
            car.Mode = "accelerating";
        }

        if (Input.GetKeyUp(KeyCode.W))
        {
            car.Mode = "cruising";
        }

        if (Input.GetKeyDown(KeyCode.S))
        {
            car.Mode = "braking";
        }

        if (Input.GetKeyUp(KeyCode.S))
        {
            car.Mode = "cruising";
        }

        if (Input.GetKeyDown(KeyCode.E))
        {
            car.ShiftGear(1);
        }

        if (Input.GetKeyDown(KeyCode.Q))
        {
            car.ShiftGear(-1);
        }

        if (car.OmegaE > 7000)
        {
            car.ShiftGear(1);
        }
    }
コード例 #2
0
 //  Event handling method for the "Shift Up" button
 public void ShiftUpButtonClicked(object source, EventArgs e)
 {
     car.ShiftGear(1);
 }
コード例 #3
0
    //private bool isGnd = false;


    private void FixedUpdate()
    {
        //중력
        if (transform.position.y > 0.05)
        {
            vel += -9.81f * Time.fixedDeltaTime;
        }
        else
        {
            vel = 0f;
        }
        carRB.velocity = new Vector3(0f, vel, 0f);


        // //max rpm 도달 시간 출력
        // if (car.OmegaE <= 8000.0)
        // {
        //
        // }

        realtime += Time.fixedDeltaTime;


        //  Display the current time
        timeTextBox.text = "" + realtime;
        //timeTextBox.text = "" + (float)car.GetTime() * realtime;

        //  Convert the velocity from m/s to km/hr and
        //  only show integer values
        velocityTextBox.text = "" + (int)(car.GetVx() * 3.6);      //시간과 관련

        if ((int)(car.GetVx() * 3.6) < 271)
        {
            maxSpeedTime.text = realtime + "";
        }

        this.transform.Translate(new Vector3(0f, 0f, (float)(car.GetVx() * 3.6 * (float)timeIncrement)));   //거리=속도*시간
        //Debug.Log((float)(car.GetVx() * 3.6 * (float)timeIncrement));

        //  Only show integer values for rpm, gear number,
        //  and distance.
        rpmTextBox.text      = "" + (int)car.OmegaE;
        gearTextBox.text     = "" + (int)car.GearNumber;
        distanceTextBox.text = "" + (int)car.GetX();


        car.Mode = "accelerating";  //임시
        if (Input.GetKey(KeyCode.W))
        {
            car.Mode = "accelerating";
        }
        else if (Input.GetKey(KeyCode.Space))
        {
            car.Mode = "braking";
        }
        else
        {
            car.Mode = "accelerating";  //임시
            //car.Mode = "cruising";
        }

        if (Input.GetKeyDown(KeyCode.E) || car.OmegaE > 7500)   //테스트
        {
            car.ShiftGear(1);
        }
        if (Input.GetKeyDown(KeyCode.Q))
        {
            car.ShiftGear(-1);
        }

        //  Update the car velocity and position at the next
        //  time increment.
        timeIncrement = 0.06 * tempDiv;  //시간과 관련
        car.UpdateLocationAndVelocity(timeIncrement);

        //  Compute the new engine rpm value
        double rpm = car.GetVx() * 60.0 * car.GetGearRatio()
                     * car.FinalDriveRatio / (2.0 * Math.PI * car.WheelRadius); //시간과 관련

        car.OmegaE = rpm;

        // rpm이 redline을 넘어서면 Warning
        // rpm이 8000을 넘어서면 엔진 정지
        messageTextBox.text = "";
        if (car.OmegaE > car.Redline)
        {
            messageTextBox.text = "Warning: Exceeding redline rpm";
        }
        if (car.OmegaE > 8000.0)
        {
            messageTextBox.text = "You have blown the engine!";
            //gameTimer.Stop();
        }
    }