国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Unity 3D汽車模擬駕駛期末大作業(yè)

這篇具有很好參考價值的文章主要介紹了Unity 3D汽車模擬駕駛期末大作業(yè)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

前言

  1. 這個學(xué)期馬上就要結(jié)束,unity要求做個項目,每到考試周,就喜歡上了黑夜。。。。。。。。。。。。。。。。

  2. 我是做了一個汽車模擬,emmmm…勉強算吧

  3. 總共有六個場景
    3.1 登錄注冊場景
    3.2 加載場景
    3.3 選擇場景
    3.4 迷宮地圖場景
    3.5 夜晚道路場景
    3.6 科目二模擬場景

  4. 汽車模型和和晚上的場景是store免費找的,迷宮和科目二模擬是搭的,很簡陋,沒眼看.

  5. 一些功能都是網(wǎng)上零零碎碎學(xué)的然后自己去摸索的.

  6. 總的來說開始很想die,到后面慢慢就熟悉了,依然想die

  7. 最后做出來還是挺…不錯的.


錄屏

Automobile simulation

一登陸注冊場景

  • 有密碼登錄面板,注冊賬號面板,設(shè)置面板
    Unity,3D汽車模擬,駕駛模擬,期末大作業(yè),Unity代碼
    Unity,3D汽車模擬,駕駛模擬,期末大作業(yè),Unity代碼
    Unity,3D汽車模擬,駕駛模擬,期末大作業(yè),Unity代碼
    代碼:

using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;public class LoginTest : MonoBehaviour{
    public InputField user;
    public InputField pass;
    public InputField r_User;
    public InputField r_Pass;
    public InputField r_CPass;
    public Text text;
    public GameObject registerPanel;
    public GameObject settingPanel;
    public Toggle toggle;
    public Slider slider;
    string rUser = "";
    string rPass = "";
    string rCPass = "";
    AudioSource au;
    // Start is called before the first frame update
    void Start()
    {
        user = user.GetComponent<InputField>();
        pass = pass.GetComponent<InputField>();
        text = text.GetComponent<Text>();
        r_User = r_User.GetComponent<InputField>();
        r_CPass = r_CPass.GetComponent<InputField>();
        r_Pass = r_Pass.GetComponent<InputField>();
        toggle = toggle.GetComponent<Toggle>();
        slider = slider.GetComponent<Slider>();
        au = GetComponent<AudioSource>();
        //user:123456
        //pass:888888
    }
    public void ActiveSettingPanel()
    {
        settingPanel.SetActive(true);
    }
    public void CloseSettingPanel()
    {
        settingPanel.SetActive(false);
    }


    public void ActiveRegisterPanel()
    {
        registerPanel.SetActive(true);
        r_User.text = "";
        r_Pass.text = "";
        r_CPass.text = "";
    }
    public void DisActiveRegisterPanel()
    {
        rUser = r_User.text;
        rPass = r_Pass.text;
        rCPass = r_CPass.text;
        if (rUser!=""&&rPass==rCPass&&rPass!=null)
        {
            registerPanel.SetActive(false);
        }
        else
        {
            r_User.text = "";
            r_Pass.text = "";
            r_CPass.text = "";
        }
        
    }
    public void CloseRegisterPanel()
    {
        registerPanel.SetActive(false);
    }
    public void OnLogin()
    {
        if (user.text ==rUser&&pass.text==rPass&&pass.text==rCPass&&rPass!="")
        {
            print("登錄成功");
            text.text = "賬號密碼正確,登錄成功";
            Invoke("ClearFailText", 1);
            text.color = Color.green;
            Invoke("GotoLoadingScene",1);
        }
        else
        {
            print("登錄失敗");
            user.text = "";
            pass.text = "";
            text.text = "賬號或密碼錯誤,登錄失敗";
            Invoke("ClearFailText",1);
            text.color = Color.red;
        }
        
    }
    public void ClearFailText()
    {
        text.text = "";
    }
    public void GotoLoadingScene()
    {
        UnityEngine.SceneManagement.SceneManager.LoadScene(1);//跳轉(zhuǎn)場景
    }
    // Update is called once per frame
    void Update()
    {
        au.mute = toggle.isOn;
        au.volume = slider.value;
    }}

二加載場景

Unity,3D汽車模擬,駕駛模擬,期末大作業(yè),Unity代碼
代碼:

using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;public class EnterLoading : MonoBehaviour{
    float t = 0;
    Slider slider;
    public Text text;
    // Start is called before the first frame update
    void Start()
    {
        slider = GetComponent<Slider>();
        text = text.GetComponent<Text>();
        text.text = "";
        slider.value = 0;
    }

    // Update is called once per frame
    void Update()
    {
        t += Time.deltaTime;
        slider.value = t * 10;
        text.text = (int)slider.value + "%";
        if (t >= 10)
        {
            slider.value = 100;
            text.text = 100 + "%";
            UnityEngine.SceneManagement.SceneManager.LoadScene(2);
        }
    }}

三選擇場景

Unity,3D汽車模擬,駕駛模擬,期末大作業(yè),Unity代碼
場景轉(zhuǎn)換和轉(zhuǎn)換效果代碼:

using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.SceneManagement;using UnityEngine.UI;public class SceneLoad : MonoBehaviour{
    public Image image_Effect;
    public float speed = 1;
    void Start()
    {
        StartCoroutine(SceneLoadIn());
    }
    public void OnClick_Btn_LoadScene_02(string SceneName)
    {
        StartCoroutine(SceneLoadOut(SceneName));
    }
    //淡出
    IEnumerator SceneLoadOut(string SceneName)
    {
        Color tempColor = image_Effect.color;
        tempColor.a = 0;
        image_Effect.color = tempColor;
        while (image_Effect.color.a < 1)
        {
            //Time.deltaTime 指的是當(dāng)前這一幀。

            image_Effect.color += new Color(0, 0, 0, speed * Time.deltaTime);
            yield return null;
        }
        SceneManager.LoadScene(SceneName);
    }
    //淡入
    IEnumerator SceneLoadIn()
    {
        Color temColor = image_Effect.color;
        temColor.a = 0;
        image_Effect.color = temColor;
        while (image_Effect.color.a > 0)
        {
            image_Effect.color += new Color(0, 0, 0, -speed * Time.deltaTime);
            yield return null;
        }
    }}

環(huán)島場景

  1. 攝像機跟著汽車代碼

using System;using System.Collections;using System.Collections.Generic;using UnityEngine;public class CameraFollow : MonoBehaviour{
    [SerializeField] private Vector3 offset;
    [SerializeField] private Transform target;
    [SerializeField] private float translateSpeed;
    [SerializeField] private float rotationSpeed;

    private void FixedUpdate()
    {
        HandleTranslation();
        HandleRotation();
    }

    private void HandleTranslation()
    {
        var targetPosition = target.TransformPoint(offset);
        transform.position = Vector3.Lerp(transform.position, targetPosition, translateSpeed * Time.deltaTime);
    }

    private void HandleRotation()
    {
        var direction = target.position - transform.position;
        var rotation = Quaternion.LookRotation(direction, Vector3.up);
        transform.rotation = Quaternion.Lerp(transform.rotation, rotation, rotationSpeed * Time.deltaTime);
    }}

  1. 汽車加速剎車等聲音代碼:

using System.Collections;using System.Collections.Generic;using UnityEngine;public class AudioManage : MonoBehaviour{
    AudioSource au;
    public AudioClip[] clip = new AudioClip[4];
    // Start is called before the first frame update
    void Start()
    {
        au = GetComponent<AudioSource>();
    }
    public void PlayAudio(int num)
    {
        au.clip = clip[num];
        au.Play();
    }
    // Update is called once per frame
    void Update()
    {
        
    }}

  1. 汽車移動控制,車燈效果,加速特效等代碼

using System;using System.Collections;using System.Collections.Generic;using UnityEngine;public class CarController1 : MonoBehaviour{
    AudioManage audioManage;

    [SerializeField] public GameObject text;

    public GameObject lig;
    int li=0;

    [SerializeField] public GameObject effect1;
    [SerializeField] public GameObject effect2;

    private const string HORIZONTAL = "Horizontal";
    private const string VERTICAL = "Vertical";

    private float HorizontalInput;
    private float verticalInput;
    private float currentSteerAngle;
    private float currentbreakForce;
    private bool isBreaking;

    [SerializeField] private float motorForce;
    [SerializeField] private float breakForce;
    [SerializeField] private float maxSteerAngle;

    [SerializeField] private WheelCollider frontLeftWheelCollider;
    [SerializeField] private WheelCollider frontRightWheelCollider;
    [SerializeField] private WheelCollider rearLeftWheelCollider;
    [SerializeField] private WheelCollider rearRightWheelCollider;

    [SerializeField] private Transform frontLeftWheelTransform;
    [SerializeField] private Transform frontRightWheelTransform;
    [SerializeField] private Transform rearLeftWheelTransform;
    [SerializeField] private Transform rearRightWheelTransform;

    void Start()
    {
        audioManage = GameObject.Find("AudioManage").GetComponent<AudioManage>();
    }
    private void FixedUpdate()
    {
        //Time.timeScale = 1.0f;
        //text.SetActive(false);
        GetInput();
        HandleMotor();
        HandleSteering(); 
        UpdateWheels();
    }

    private void GetInput()
    {
        HorizontalInput = Input.GetAxis(HORIZONTAL);
        verticalInput = Input.GetAxis(VERTICAL);
        isBreaking = Input.GetKey(KeyCode.Space);
        //isShift = Input.GetKey(KeyCode.LeftShift);
    }

    private void HandleMotor()
    {
        frontLeftWheelCollider.motorTorque = verticalInput * motorForce;
        frontRightWheelCollider.motorTorque = verticalInput * motorForce;
        
        if (Input.GetKeyDown(KeyCode.LeftShift))
        {
            audioManage.PlayAudio(0);
            effect1.SetActive(true);
            effect2.SetActive(true);
            frontLeftWheelCollider.motorTorque = 20000000.0f;
            frontRightWheelCollider.motorTorque = 20000000.0f;
        }
        if (Input.GetKey(KeyCode.L))
        {
            if (li == 0)
            {
                lig.SetActive(true);
                li = 1;
            }
            else
            {
                lig.SetActive(false);
                li = 0;
            }
        }
        if (Input.GetKeyDown(KeyCode.X))
        {
            audioManage.PlayAudio(1);
            frontLeftWheelCollider.motorTorque = -20000000.0f;
            frontRightWheelCollider.motorTorque = -20000000.0f;
        }
        if (Input.GetKeyDown(KeyCode.W))
            audioManage.PlayAudio(3);
        if (Input.GetKeyDown(KeyCode.S))
        {
            audioManage.PlayAudio(2);
            effect1.SetActive(false);
            effect2.SetActive(false);
        }
        currentbreakForce = isBreaking ? breakForce : 0f;

        if (isBreaking)
        {
            ApplyBreaking();
        }
    }

    private void ApplyBreaking()
    {
        frontRightWheelCollider.brakeTorque = currentbreakForce;
        frontLeftWheelCollider.brakeTorque = currentbreakForce;
        rearRightWheelCollider.brakeTorque = currentbreakForce;
        rearRightWheelCollider.brakeTorque = currentbreakForce;
    }

    private void HandleSteering()
    {
        currentSteerAngle = maxSteerAngle * HorizontalInput;
        frontLeftWheelCollider.steerAngle = currentSteerAngle;
        frontRightWheelCollider.steerAngle = currentSteerAngle;
    }
    private void UpdateWheels()
    {
        UpdateSinglewheel(frontLeftWheelCollider, frontLeftWheelTransform);
        UpdateSinglewheel(frontRightWheelCollider, frontRightWheelTransform);
        UpdateSinglewheel(rearRightWheelCollider, rearRightWheelTransform);
        UpdateSinglewheel(rearLeftWheelCollider, rearLeftWheelTransform );
    }

    private void UpdateSinglewheel(WheelCollider wheelCollider, Transform wheelTransform)
    {
        Vector3 pos;
        Quaternion rot;
        wheelCollider.GetWorldPose(out pos, out rot);
        wheelTransform.rotation = rot;
        wheelTransform.position = pos;
    }}

  1. 時間代碼和計時代碼

using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;using System;public class GetTime1 : MonoBehaviour{
    public Text TxtCurrentTime;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        DateTime NowTime = DateTime.Now.ToLocalTime();
        TxtCurrentTime.text = NowTime.ToString("時間:yyyy-MM-dd HH:mm:ss");
    }}

using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;public class time : MonoBehaviour{
    private int hour;
    private int minute;
    private int second;
    private int millisecond;

    //已經(jīng)花費的時間
    float timeSpeed = 0.0f;

    //顯示時間區(qū)域的文本
    Text text_timeSpeed;
    // Start is called before the first frame update
    void Start()
    {
        text_timeSpeed = GetComponent<Text>();
    }

    // Update is called once per frame
    void Update()
    {
        timeSpeed += Time.deltaTime;
        hour = (int)timeSpeed / 3600;
        minute = ((int)timeSpeed - hour * 3600) / 60;
        second = (int)timeSpeed - hour * 3600 - minute * 60;
        //text_timeSpeed.text = string.Format("{0:D2}:{1:D2}:{2:D2}", hour, minute, second);
        millisecond = (int)((timeSpeed - (int)timeSpeed) * 1000);
        text_timeSpeed.text = string.Format("計時:{0:D2}:{1:D2}:{2:D2}.{3:D3}", hour, minute, second, millisecond);
    }}

科目二場景

  1. 碰撞檢測觸碰白線代碼

using System.Collections;using System.Collections.Generic;using UnityEngine;public class delay : MonoBehaviour{
    [SerializeField] public GameObject text;
    private void OnCollisionEnter(Collision collision)
    {
        //Time.timeScale = 0;
        
        text.SetActive(true);
    }}

  1. 進(jìn)入模擬測試前的白線和結(jié)束后的白線代碼

using System.Collections;using System.Collections.Generic;using UnityEngine;public class Tanchuan : MonoBehaviour{
    int i = 0;
    public GameObject text;
    private void OnCollisionEnter(Collision collision)
    {
        if (i==0)
        {
            i = 1;
            Time.timeScale = 0;
            text.SetActive(true);
        }
        
    }}


總結(jié)

三個場景里有相同的代碼腳本,直接復(fù)制就行
這是個團(tuán)隊干的活!!一個人干會累死!


https://download.csdn.net/download/weixin_44954896/85583972?spm=1001.2014.3001.5503
工程文件已上傳,自取
包括所有素材源代碼。打開即可運行。文章來源地址http://www.zghlxwxcb.cn/news/detail-401000.html

到了這里,關(guān)于Unity 3D汽車模擬駕駛期末大作業(yè)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 【自動駕駛汽車量子群粒子過濾器】用于無人駕駛汽車列車定位的量子粒子濾波研究(Matlab代碼實現(xiàn))

    【自動駕駛汽車量子群粒子過濾器】用于無人駕駛汽車列車定位的量子粒子濾波研究(Matlab代碼實現(xiàn))

    ???????? 歡迎來到本博客 ???????? ??博主優(yōu)勢: ?????? 博客內(nèi)容盡量做到思維縝密,邏輯清晰,為了方便讀者。 ?? 座右銘: 行百里者,半于九十。 ?????? 本文目錄如下: ?????? 目錄 ??1 概述 ??2 運行結(jié)果 ??3?參考文獻(xiàn) ??4 Matlab代碼實現(xiàn) 對于無人

    2024年02月15日
    瀏覽(25)
  • Python綜合練習(xí):期末大作業(yè)使用openpyxl進(jìn)行模擬學(xué)生宿舍管理系統(tǒng)設(shè)計與開發(fā)

    Python綜合練習(xí):期末大作業(yè)使用openpyxl進(jìn)行模擬學(xué)生宿舍管理系統(tǒng)設(shè)計與開發(fā)

    1.1 問題背景 隨著辦公智能化的發(fā)展,為方便對大學(xué)生宿舍的動態(tài)管理,宿舍管理系統(tǒng)儲存了每個宿舍學(xué)生的基本個人信息,同時需要針對一些特殊情況,如轉(zhuǎn)專業(yè)、退學(xué)等,對宿舍的信息實現(xiàn)動態(tài)調(diào)整,支持顯示、增加、刪除、修改、查詢成員信息,從而實現(xiàn)宿舍管理員對

    2024年02月07日
    瀏覽(23)
  • gl-opendrive插件(車倆3D仿真模擬自動駕駛)

    gl-opendrive插件(車倆3D仿真模擬自動駕駛)

    本插件基于免費opendrive開源插件、Threejs和Webgl三維技術(shù)、vue前端框架,blender開源建模工具等進(jìn)行二次開發(fā)。該插件由本人獨立開發(fā)以及負(fù)責(zé),目前處于demo階段,功能還需待完善,由于開發(fā)倉促代碼還需優(yōu)化。 兩個版本: 1.vue版本pc端可視化展示 2.非vue版本支持內(nèi)嵌到安卓,

    2023年04月27日
    瀏覽(38)
  • gl-opendrive插件(車倆3D仿真模擬自動駕駛)

    gl-opendrive插件(車倆3D仿真模擬自動駕駛)

    本插件基于免費opendrive開源插件、Threejs和Webgl三維技術(shù)、vue前端框架,blender開源建模工具等進(jìn)行二次開發(fā)。該插件由本人獨立開發(fā)以及負(fù)責(zé),目前處于demo階段,功能還需待完善,由于開發(fā)倉促代碼還需優(yōu)化。 兩個版本: 1.vue版本pc端可視化展示 2.非vue版本支持內(nèi)嵌到安卓,

    2024年02月08日
    瀏覽(21)
  • 期末大作業(yè)圖書管理系統(tǒng)(c++)源代碼

    期末大作業(yè)圖書管理系統(tǒng)(c++)源代碼

    功能展示 運行效果 : 主界面: 圖書管理界面: 讀者管理界面: 借還書管理界面:

    2024年02月11日
    瀏覽(88)
  • final-期末大作業(yè)-制作AR射箭小游戲(Unity AR配置詳細(xì)教程)

    final-期末大作業(yè)-制作AR射箭小游戲(Unity AR配置詳細(xì)教程)

    鏈接: github倉庫 bilibili視頻 大作業(yè)要求: 制作一款特定技術(shù)應(yīng)用小游戲,并提交技術(shù)報告。 內(nèi)容(請參考以下技術(shù)主題,但不限于這些主題): 運用手機拍若干全景圖,貼到天空盒或球型天空,做一個簡單校園漫游功能。 粒子系統(tǒng)效果制作,必須帶一個控制組件,控制粒子

    2024年02月06日
    瀏覽(30)
  • 合肥工業(yè)大學(xué)機器視覺期末復(fù)習(xí) 課件梳理(穿插作業(yè)中的偽代碼)

    合肥工業(yè)大學(xué)機器視覺期末復(fù)習(xí) 課件梳理(穿插作業(yè)中的偽代碼)

    第一部分:低層次視覺 1、濾波器 2、梯度—邊緣;梯度—能量(線裁剪) 3、模板匹配;二值圖像分析 4、紋理 第二部分:中層次視覺 5、霍夫變換 6、分割 7、局部不變特征——檢測、描述和匹配 8、立體 第三部分:高層次的視覺 9、實例識別 10、監(jiān)督分類的對象檢測 11、支持向

    2024年02月02日
    瀏覽(27)
  • 安卓期末大作業(yè)(AndroidStudio開發(fā)),垃圾分類app,代碼有注釋,能正常運行

    安卓期末大作業(yè)(AndroidStudio開發(fā)),垃圾分類app,代碼有注釋,能正常運行

    安卓期末大作業(yè) ?app使用的是sqlite數(shù)據(jù)庫,使用的核心類及其組件:Base Adapter,F(xiàn)ragment,View Pager,Alert Dialog.Builder,Option,Animation Draw able(關(guān)鍵幀動畫),Media Player(視頻),Count Down Timer(倒計時 廣告頁用),Spinner等 該分類助手的功能是管理員先登錄進(jìn)入后臺界面,將數(shù)據(jù)

    2024年02月12日
    瀏覽(19)
  • unity期末作業(yè)-兩個簡單小游戲游戲-躲避障礙和跑酷(附下載鏈接和gif動態(tài)圖演示)

    unity期末作業(yè)-兩個簡單小游戲游戲-躲避障礙和跑酷(附下載鏈接和gif動態(tài)圖演示)

    游戲角色為一個小人,天上不時會掉落障礙物,人物撞到了會掉生命值,人物可以左右移動跳躍來躲避,帶游戲音效,比較簡單!具體情況如下所示: 點我下載源文件和exe導(dǎo)出文件》》》》》》》 角色可以上下左右移動,J發(fā)射子彈k跳躍,只有在跳板上才可以跳躍,可以吃能

    2024年02月04日
    瀏覽(35)
  • unity3d在汽車鄰域應(yīng)用淺談

    Unity3D是一款實時3D內(nèi)容創(chuàng)作軟件,它在汽車應(yīng)用創(chuàng)新方面發(fā)揮了重要作用。以下是Unity3D在汽車應(yīng)用創(chuàng)新方面的幾個關(guān)鍵領(lǐng)域: 智能座艙:Unity3D為汽車智能座艙提供了解決方案,通過重新定義座艙設(shè)計,將車艙打造成全新的“第三空間”。這種解決方案不僅提供了炫目的視效

    2024年01月24日
    瀏覽(47)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包