Unity3D iBeacon Android应用程序已停止

Unity3D iBeacon Android应用程序已停止,android,unity3d,ibeacon,ibeacon-android,estimote,Android,Unity3d,Ibeacon,Ibeacon Android,Estimote,我刚刚开始使用Unity3D,我的学校项目包括使用iBeacons并用我的移动设备检测它们。我正在做一个2D项目,在我的场景中,我有一个空的游戏对象,其中包含处理iBeacon检测的代码: public class iBeaconReceiverExample : MonoBehaviour { private Vector2 scrolldistance; private List<Beacon> mybeacons = new List<Beacon>

我刚刚开始使用Unity3D,我的学校项目包括使用iBeacons并用我的移动设备检测它们。我正在做一个2D项目,在我的场景中,我有一个空的游戏对象,其中包含处理iBeacon检测的代码:

public class iBeaconReceiverExample : MonoBehaviour
{
    private Vector2 scrolldistance;
    private List<Beacon> mybeacons = new List<Beacon>();
    private bool scanning = true;
    private bool guion = false;
    public GameObject Nipper;
    // Use this for initialization
    void Start()
    {
        iBeaconReceiver.BeaconRangeChangedEvent += OnBeaconRangeChanged;
        iBeaconReceiver.BluetoothStateChangedEvent += OnBluetoothStateChanged;
        iBeaconReceiver.CheckBluetoothLEStatus();
        Debug.Log("Listening for beacons");
    }

    void OnDestroy()
    {
        iBeaconReceiver.BeaconRangeChangedEvent -= OnBeaconRangeChanged;
        iBeaconReceiver.BluetoothStateChangedEvent -= OnBluetoothStateChanged;
    }

    // Update is called once per frame
    void Update()
    {
        foreach (Beacon b in mybeacons)
        {
            if (0.00 < b.accuracy && b.accuracy < 2.00)
            {
                CreateNipper();
            }
        }

    }

    public void CreateNipper()
    {
        GameObject nipper = Instantiate(Nipper, new Vector3(1, 1, -7), Quaternion.identity) as GameObject;
        nipper.transform.SetParent(transform);
    }

    private void OnBluetoothStateChanged(BluetoothLowEnergyState newstate)
    {
        switch (newstate)
        {
            case BluetoothLowEnergyState.POWERED_ON:
                iBeaconReceiver.Init();
                Debug.Log("It is on, go searching");
                break;
            case BluetoothLowEnergyState.POWERED_OFF:
                //iBeaconReceiver.EnableBluetooth();
                Debug.Log("It is off, switch it on");
                break;
            case BluetoothLowEnergyState.UNAUTHORIZED:
                Debug.Log("User doesn't want this app to use Bluetooth, too bad");
                break;
            case BluetoothLowEnergyState.UNSUPPORTED:
                Debug.Log("This device doesn't support Bluetooth Low Energy, we should inform the user");
                break;
            case BluetoothLowEnergyState.UNKNOWN:
            case BluetoothLowEnergyState.RESETTING:
            default:
                Debug.Log("Nothing to do at the moment");
                break;
        }
    }

    private void OnBeaconRangeChanged(List<Beacon> beacons)
    {
        // 
        foreach (Beacon b in beacons)
        {
            if (mybeacons.Contains(b))
            {
                mybeacons[mybeacons.IndexOf(b)] = b;
            }
            else
            {
                // this beacon was not in the list before
                // this would be the place where the BeaconArrivedEvent would have been spawned in the the earlier versions
                mybeacons.Add(b);
            }
        }
        foreach (Beacon b in mybeacons)
        {
            if (b.lastSeen.AddSeconds(10) < DateTime.Now)
            {
                // we delete the beacon if it was last seen more than 10 seconds ago
                // this would be the place where the BeaconOutOfRangeEvent would have been spawned in the earlier versions
                mybeacons.Remove(b);
            }
        }
    }
公共类IBeAconReceiver示例:MonoBehavior
{
专用矢量2滚动距离;
私有列表mybeacons=新列表();
私有布尔扫描=真;
private bool guion=false;
公共游戏对象钳;
//用于初始化
void Start()
{
iBeaconReceiver.BeaconRangeChangeEvent+=OnBeaconRangeChanged;
iBeaconReceiver.BluetoothStateChangeEvent+=OnBluetoothStateChanged;
iBeaconReceiver.CheckBluetoothLEStatus();
Log(“监听信标”);
}
void OnDestroy()
{
iBeaconReceiver.BeaconRangeChangeEvent-=OnBeaconRangeChanged;
iBeaconReceiver.BluetoothStateChangeEvent-=OnBluetoothStateChanged;
}
//每帧调用一次更新
无效更新()
{
foreach(mybeacons中的信标b)
{
如果(0.00
“Init()”方法启动iBeacon插件并开始在我的移动设备周围搜索iBeacon。我唯一关心的是我有两个场景,一旦我转到另一个场景(随机场景)并返回到原始场景(包含iBeaconReceiveExample脚本的场景),我的应用程序“不幸地”(游戏名称)崩溃已经停止。”

我曾使用adb Logcat跟踪我设备的日志,但它对我没有任何帮助。我曾尝试制作两个全新的场景(认为我的场景可能疯了),但没有任何效果。当我没有将此脚本附加到我的游戏对象时,我的应用程序不会崩溃,很明显问题一定在这里的某个地方

有人在Unity上玩iBeacons时遇到过这个问题吗?这个问题的解决方案是什么

先谢谢你!:)