互動按鈕 課程,你學到如何建立螢幕上的按鈕作為菜單.行動等更多用處。其實如果需要提供互動功能的介面,也可以等到玩家碰觸到遊戲中的一些物件,比如門.開關或甚至是一些非玩家的角色等等

Untitled

開啟專案

這個單元我們將使用一個已存在的專案  Dungeon Delve  來作為範例。首先請參考下圖的方式來開啟 Studio

https://developer.roblox.com/assets/bltffd6e372938508a3/270a3dbc41e50102adbc79241a2dfdff.png

建立一個互動區域(Prompt)

螢幕上的互動區域可透過一個 [ProximityPrompt](<https://developer.roblox.com/en-us/api-reference/class/ProximityPrompt>) 物件來生成,作為 [Attachment](<https://developer.roblox.com/en-us/api-reference/class/Attachment>)[BasePart](<https://developer.roblox.com/en-us/api-reference/class/BasePart>), 或 [Model](<https://developer.roblox.com/en-us/api-reference/class/Model>) 的上層物件

  1. 選擇 3D 視圖裡的牢房門模型,或透過 Explorer 視窗(Workspace → PromptObjects → PrisonDoor)

https://developer.roblox.com/assets/blt9e9092fc8ca94aa1/91a04436f3520a7aea87c0bab99635ab.jpg

https://developer.roblox.com/assets/blt6fc949c5888a12f1/f83b5cde3abafa1841248fdcaa339438.png

  1. 展開後選擇 Door 物件

https://developer.roblox.com/assets/blt9832702aec6f4313/ff617281c8714857dca49443f20af84b.png

  1. 放置一個互動區域於一個 [Attachment](<https://developer.roblox.com/en-us/api-reference/class/Attachment>) 讓你相對於直接放置在零件或模型上,有更多控制權去決定互動發生的位置。插入一個新的 Attachment 並更名為 PromptAttachment

https://developer.roblox.com/assets/blt4abb98da8ead91a8/75dfb8c59467b22d3c7f57f75ca85258.png

  1. 找到新 attachment 的 Position 屬性,並設定它為 -2.25, -0.5, -0.5,這將會把它移到門孔的前方

https://developer.roblox.com/assets/blt15446b22caf85b6f/75b576650bd5fa3e9d712de2190168b5.jpg

https://developer.roblox.com/assets/bltb14e7b0240c7402d/6b1274ab45fdbbb4dc7b22f667fe7a4a.png

  1. 滑鼠指標移到 PromptAttachment 並插入一個新的 ProximityPrompt 物件

https://developer.roblox.com/assets/bltd2f345dbc5be259d/786e049c113f6dc78dc76d2d89506f2c.png