iT邦幫忙

2021 iThome 鐵人賽

DAY 8
1
自我挑戰組

從0開始的UnityAR手機遊戲開發系列 第 8

[第八天]從0開始的UnityAR手機遊戲開發-如何將模型設置在圖卡上和腳本解說

  • 將模型設置在圖卡上

先將ImageTarget下的子物件刪除
https://ithelp.ithome.com.tw/upload/images/20210922/20140569OcDCJk28Sj.png

在Project找到從商店下載的模型Prefab,拖曳到ImageTarget下成為子物件並調整大小移動至卡片上方。
點擊子物件開啟Inspector的元件資訊將Transform以外的元件都刪除(本次章節用不到)
https://ithelp.ithome.com.tw/upload/images/20210922/20140569HF336qAk9L.png

如果找不到Prefab可以在Project點擊https://ithelp.ithome.com.tw/upload/images/20210922/20140569BuuLQM1gwb.pngSearch by type選擇Prefab後,旁邊會出現一個勾勾然後跳出Project的所有Prefab物件,再按一次可以取修勾選返回原來的樣子。
https://ithelp.ithome.com.tw/upload/images/20210922/20140569pAhPPuTT0y.png

按下啟動,如果電腦有內建或外接的鏡頭Unity會抓取那個鏡頭來使用,Unity拍到辨識圖卡時就會出現剛剛新建的模型
https://ithelp.ithome.com.tw/upload/images/20210922/20140569s40v20Atal.png


  • 腳本解說

DefaultTrackableEventHandler為控制ImageTarget子物件是否顯示的腳本,這一段落會在此做簡單介紹

點選ImageTarget物件開啟Inspector的元件資訊,點擊2下DefaultTrackableEventHandler開啟腳本
https://ithelp.ithome.com.tw/upload/images/20210922/20140569bt1CCpamcd.png

如果沒有開啟或不是以Visual Studio2019開啟的話,可以到Edit→Preferences→External Tools→Extemal Script Editor選擇Browse..找到你的Visual Studio2019位置按開啟按鈕就可以更換了。
https://ithelp.ithome.com.tw/upload/images/20210922/20140569hogaJx5QVc.png

DefaultTrackableEventHandler腳本介紹
https://ithelp.ithome.com.tw/upload/images/20210922/20140569aA3y6hM8Oz.png
https://ithelp.ithome.com.tw/upload/images/20210922/20140569nnYwnyVG38.png
https://ithelp.ithome.com.tw/upload/images/20210922/20140569EIIrzcEg9C.png
https://ithelp.ithome.com.tw/upload/images/20210922/20140569AHT8GwGy7I.png


以前在用Vuforia時此腳本是有Event顯示的(下圖所示),這次弄不知道為啥弄不出來就改為腳本介紹了
https://ithelp.ithome.com.tw/upload/images/20210922/20140569PTbNXqEe50.png


下一張章節會介紹Unity寫程式的基本語法。


上一篇
[第七天]從0開始的UnityAR手機遊戲開發-介紹Unity的Asset Store和從Asset Store或網路下載3D模型
下一篇
[第九天]從0開始的UnityAR手機遊戲開發-介紹Unity寫程式的基本語法。
系列文
從0開始的UnityAR手機遊戲開發30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言