網(wǎng)上有很多關(guān)于中國(guó)刷卡機(jī)pos機(jī)按鍵,5.Prefab與碰撞檢測(cè)的知識(shí),也有很多人為大家解答關(guān)于中國(guó)刷卡機(jī)pos機(jī)按鍵的問(wèn)題,今天pos機(jī)之家(www.tjfsxbj.com)為大家整理了關(guān)于這方面的知識(shí),讓我們一起來(lái)看下吧!
本文目錄一覽:
中國(guó)刷卡機(jī)pos機(jī)按鍵
9.增加手機(jī)操作按鈕本章帶大家開(kāi)發(fā)的游戲要在手機(jī)上運(yùn)行的話,由于手機(jī)上沒(méi)有左右按鍵,所以,在游戲中必須添加左右按鈕來(lái)實(shí)現(xiàn)角色的移動(dòng)。
9.1創(chuàng)建左按鈕在層級(jí)窗口中選擇 Create -> UI -> Button,此時(shí)在層級(jí)窗口中增加一個(gè)按鈕,在場(chǎng)景視圖中看不到可雙擊層級(jí)窗口中的按鈕對(duì)象,將按鈕命名為 LButton。將錨點(diǎn)設(shè)置為左下角,設(shè)置如下:
Rect Transform:PosX、PosY、PosZ:100、100、0;width="360px",height="auto" />
將左按鈕圖片拖拽到 Image(Script) 中的 Source Image 上。
刪除按鈕上的文本:
在層級(jí)窗口中單擊按鈕左側(cè)的“展開(kāi)箭頭”,選中 Text 后右擊選擇 Delete。
9.2 復(fù)制左按鈕生成右按鈕在層級(jí)窗口中選擇 LButton,右擊后選擇 Duplicate;可以看到在層級(jí)窗口中生成一個(gè)名稱為 LButton(1) 的按鈕,重命名為 RButton,將錨點(diǎn)設(shè)置為右下角,并設(shè)置如下:
Rect Transform:PosX、PosY、PosZ:-100、100、0;width="360px",height="auto" />
將左按鈕圖片拖拽到 Image(Script) 中的 Source Image 上。
9.3 實(shí)現(xiàn)按鈕操作要實(shí)現(xiàn)按鈕操作,首先編寫(xiě)使角色左右移動(dòng)的方法,然后在按鈕的檢視器窗口中配置即可。
在角色的控制器中編寫(xiě)按鈕操作的方法,代碼如下:
using System.Collections;using System.Collections.Generic;using UnityEngine;public class PlayerController : MonoBehaviour{ // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.LeftArrow) && transform.position.x > -10) { transform.Translate(-1, 0, 0); } if (Input.GetKeyDown(KeyCode.RightArrow) && transform.position.x < 10) { transform.Translate(1, 0, 0); } } public void LButtonDown() { if (transform.position.x > -10) transform.Translate(-1, 0, 0); } public void RButtonDown() { if (transform.position.x < 10) transform.Translate(1, 0, 0); }}
上面的代碼中,LButtonDown 和 RButtonDown 方法為新增的代碼,分別實(shí)現(xiàn)左右按鈕按下的動(dòng)作。
指定按鈕調(diào)用對(duì)應(yīng)的方法:
在層級(jí)窗口中選中 LButton,在檢視器窗口中的 Button(Script) 項(xiàng)中單擊 OnClick 下的 + 按鈕將層級(jí)窗口中的角色 player 拖拽到 None(Object) 上然后單擊 No Function 下拉列表,選擇 PlayerController -> LButtonDown注:對(duì)應(yīng)的方法必須在代碼中使用 public 關(guān)鍵字聲明。
如下圖所示:
同樣的方法指定右按鈕調(diào)用的方法,保存游戲,運(yùn)行游戲,看看效果。
以上就是關(guān)于中國(guó)刷卡機(jī)pos機(jī)按鍵,5.Prefab與碰撞檢測(cè)的知識(shí),后面我們會(huì)繼續(xù)為大家整理關(guān)于中國(guó)刷卡機(jī)pos機(jī)按鍵的知識(shí),希望能夠幫助到大家!
