Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        if (broadcaster.instance != null)
        {
            isBroadcasterStarted = broadcaster.IsStarted();

            if (broadcaster.identity == Broadcaster.Identity.broadcaster)
            {
                PrepareData();
                broadcaster.data = data;
                broadcaster.Send();
            }
            else if (broadcaster.identity == Broadcaster.Identity.receiver)
            {
                if (Input.GetKeyDown(KeyCode.S))
                {
                    broadcaster.StopUDP();
                }
                if (Input.GetKeyDown(KeyCode.R))
                {
                    broadcaster.StartUDP();
                    broadcaster.StartListen();
                }

                data = broadcaster.data;
                DecryptData();

                if (controlledObject != null)
                {
                    controlledObject.transform.SetParent(objectContainer.transform);
                    objectContainer.transform.position = controlledObject.transform.position;
                    if (useGyroscope)
                    {
                        controlledObject.transform.localRotation = Quaternion.Lerp(controlledObject.transform.localRotation, rotation, 0.1f);
                    }
                    else
                    {
                        Quaternion rotInVec = new Quaternion(acceleration.x, acceleration.y, -acceleration.z, 0.4f);
                        controlledObject.transform.localRotation = Quaternion.Lerp(controlledObject.transform.localRotation, rotInVec, 0.1f);
                    }
                }
            }
        }
    }