看板 GameDesign 關於我們 聯絡資訊
在之前詢問了Update()的細節後 自己有去改了一下 不過還是有一些問題 主要設定的程式是這樣子 void Update(){ for (int i = 0; i < NumStrings; ++i) { ButtonsJustPressed [i] = false; CheckKeyCode (StringKeys [i], i); } } void CheckKeyCode( KeyCode code, int stringIndex ){ if( Input.GetKeyDown( code ) ) { OnStringChange( stringIndex, true ); } if( Input.GetKey( code ) && !ButtonsPressed[ stringIndex ] ){ OnStringChange( stringIndex, true ); } if( Input.GetKeyUp( code ) ){ OnStringChange( stringIndex, false ); } } 若是在物品落下時 利用長按的方法去接住 要怎麼改比較好? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.227.216.73 ※ 文章網址: https://www.ptt.cc/bbs/GameDesign/M.1442984491.A.6CD.html
cjcat2266: 按下flag = true,放開flag = false 09/23 14:26
cjcat2266: if (flag && 物件碰到) 接住(); 09/23 14:26
laikyo: 你要不要看一下Input.GetKey官方描述... 09/23 17:09
kagami91582: 其實看了很久還是看不懂(淚 09/23 23:34
tomnelson: docs.unity3d.com/ScriptReference/Input.GetKey.html 09/24 01:05
tomnelson: Input.GetKey不就是當按鍵一直被按住沒放開時會return 09/24 01:07
tomnelson: true嗎? 你應該是 GetKeyDown/GetKey/GetKeyUp 三個狀 09/24 01:09
tomnelson: 態處理那邊沒搞好,往那方向去思考一下吧! 09/24 01:10
tomnelson: 我的想法是GetKeyDown(x)後設flag(x)=true,當GetKey(x) 09/24 01:12
tomnelson: 為true且flag(x)=true維持一段時間,就去做長按的事,而 09/24 01:14
tomnelson: GetKeyUp(x)=true且flag(x)=true時,將flag(x)設成false 09/24 01:15
tomnelson: 至於"維持一段時間"那部份,可能你要試驗看看,或許用 09/24 01:16
tomnelson: counter(x)=counter(x)+1的方式就可以,未必要用到時間 09/24 01:20
tomnelson: docs.unity3d.com/ScriptReference/Time.html 09/24 01:20
tomnelson: 裡頭的 deltaTime (Time.deltaTime) 之類的,總之,你就 09/24 01:22
tomnelson: 動手&再動腦試試囉~ 09/24 01:22
kagami91582: 感謝提點 之後我是這樣子改啦 09/24 01:50
kagami91582: http://i.imgur.com/wW9CweW.png 09/24 01:51
kagami91582: 按下一個key然後不放開這樣 的確有接到物品了 09/24 01:51
kagami91582: 雖然目的是要讓他同時跑兩個啦~ 但已經先從無線迴圈 09/24 01:52
kagami91582: 跳出來了 再次感謝(淚 09/24 01:53
kagami91582: 不然已經鬼打牆一段時間 自己英文又無敵廢(炸 09/24 01:54
tomnelson: 有從 loop 裡出來就好~ 恭喜! 09/24 02:43