iT邦幫忙

2025 iThome 鐵人賽

DAY 28
0
自我挑戰組

從零開始學習Unity引擎系列 第 28

unity學習day28--製作遊戲(7)

  • 分享至 

  • xImage
  •  

還是在“CenterPivot”下面,建立空物件命名為“C_Path”,相對位置設為(0,0,0)它的作用是定位之後C區域的物件。在“C_Path”下面建立子物件立方體“C_Platform_01”, “C_Platform_01”的位置是(14,71,-1.5),縮放是(3,0.2,3)。
https://ithelp.ithome.com.tw/upload/images/20250930/20178373DJm3SkBu39.png

接著在“Scripts”下面建立腳本命名為“MovingPlatform”,寫上平台移動的腳本。
https://ithelp.ithome.com.tw/upload/images/20250930/201783731y7AZGfulH.png

把腳本掛到“C_Platform_01”,檢查器這裡的參數用默認的就好。
https://ithelp.ithome.com.tw/upload/images/20250930/20178373ScwW3P3ewz.png

然後執行看看是否會左右移動,可以看出確實移動了。
https://ithelp.ithome.com.tw/upload/images/20250930/20178373Mrplqxag9x.png

接下來複製9個一樣的並依X軸每隔6個放置1個。
https://ithelp.ithome.com.tw/upload/images/20250930/20178373bZqpCV5hLO.png

同樣是在“CenterPivot”建立一個立方體命名為“EndPlate”,相對位置設為(76,71,-1.5),縮放為(6,0.4,6),接著把“M_Grass”材質拖上去,最後把“RedCoin”拖進來並且改名為“RedCoin_04。
https://ithelp.ithome.com.tw/upload/images/20250930/20178373UadovOmF72.png

在“Scripts”下面新增腳本命名為“EndCoin”,這個腳本用來寫結束並且結算的程式碼,最後會顯示分數和重玩,不過吃到金幣加分的部分我其實沒怎麼做,因為是一個demo,也許後續會補全這方面的玩法。
https://ithelp.ithome.com.tw/upload/images/20250930/20178373iJKOkjk5ec.png

把“EndCoin”掛上“RedCoin_04,並且移除“CheckpointCoin”腳本,在吃到第四枚紅色金幣後,遊戲結束,如果沒有移除的話兩個腳本可能會衝突,而且在結束的地方設定重生點也沒有任何意義了。
https://ithelp.ithome.com.tw/upload/images/20250930/201783739XMYtKkjfx.png


上一篇
unity學習day27--製作遊戲(6)
系列文
從零開始學習Unity引擎28
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言