using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using MojingSample.CrossPlatformInput;
public class transforms : MonoBehaviour
{
public Text[] SpeedText;//屏幕输出
public GameObject cameras;//移动camera物体
private bool IsMove=true;//移动与界面显示
void Update()
{
Centers();//遥杆控制
}
//遥杆控制
public void Centers()
{
//摇杆回到中间位置
if (CrossPlatformInputManager.GetButton("CENTER"))//中心点感应
{
IsMove = true;//遥杆未控制视觉可控
SpeedText[0].text = "遥杆归位";
}
else
{
IsMove = false;//遥杆控制视觉不可控
SpeedText[0].text = "遥杆移动";
}
if (CrossPlatformInputManager.GetButton("UP"))//感应前
{
SpeedText[1].text = "向前移";
//控制前移动
cameras.transform.Translate(Vector3.forward * 0.3f * Time.deltaTime);
}
else
{
SpeedText[1].text = "wait...";
}
if (CrossPlatformInputManager.GetButton("LEFT"))//感应左
{
SpeedText[2].text = "向左转";
//控制旋转左
cameras.transform.Rotate(Vector3.down * 5 * Time.deltaTime);
}
else
{
SpeedText[2].text = "wait...";
}
if (CrossPlatformInputManager.GetButton("RIGHT"))//感应右
{
SpeedText[3].text = "向右转";
//控制旋转右
cameras.transform.Rotate(Vector3.up * 5 * Time.deltaTime);
}
else
{
SpeedText[3].text = "wait...";
}
if (CrossPlatformInputManager.GetButton("DOWN"))//感应后
{
SpeedText[4].text = "向后移";
//控制后移动
cameras.transform.Translate(Vector3.back * 0.3f * Time.deltaTime);
}
else
{
SpeedText[4].text = "wait...";
}
}
}
注:此方法主要根据mojingSDK中的CrossPlatformInputManager类进行遥杆按钮的检测,再根据需要进行简单的控制即可执行......