当我们在unity ngui中创建虚拟键盘时,同时就需要创建虚拟键盘按钮,那么unity ngui 虚拟键盘按钮是怎样创建的呢?下面我们就来学习。
1、新建一个GUITexture,重命名为JumpButton2、给JumpButton选择所需的按钮图片
3、新建如下js脚本,添加给JumpButton
[AppleScript]@script RequireComponent( GUITexture )
var jumpSpeed:float=3.0;
var controller : CharacterController ;
function Update()
{
for (var i = 0; i < Input.touchCount; i++)
{
var touch = Input.GetTouch(i);
if(touch.phase == TouchPhase.Stationary && guiTexture.HitTest(touch.position)) //按着按钮不动时
{
//do something...
}
else if(touch.phase == TouchPhase.Began && guiTexture.HitTest(touch.position)) //单击按钮时
{
controller.SimpleMove(Vector3.up * jumpSpeed);
}
}
}