Skip to content

Instantly share code, notes, and snippets.

@dattasaurabh82
Created March 16, 2017 13:33
Show Gist options
  • Save dattasaurabh82/8c1644221f39b0b6d8525218f93a9088 to your computer and use it in GitHub Desktop.
Save dattasaurabh82/8c1644221f39b0b6d8525218f93a9088 to your computer and use it in GitHub Desktop.
OSCReceiver.cs
using UnityEngine;
using System.Collections;
public class OSCRcvrCS : MonoBehaviour
{
public string RemoteIP = "127.0.0.1";
//127.0.0.1 signifies a local host (if testing locally
public int SendToPort = 7000;
public int ListenerPort = 6000;
private Osc handler;
private UDPPacketIO udp;
public string GameReceiver = "Cube";
public GameObject ReceivedGameObject;
public void Start ()
{
//Initializes on start up to listen for messages
//make sure this game object has both UDPPackIO and OSC script attached
udp = GetComponent<UDPPacketIO> ();
udp.init (RemoteIP, SendToPort, ListenerPort);
handler = GetComponent<Osc> ();
handler.init (udp);
handler.SetAllMessageHandler (AllMessageHandler);
Debug.Log ("Running");
ReceivedGameObject = GameObject.Find (GameReceiver);
}
void Update(){
}
void LateUpdate (){
}
//These functions are called when messages are received
//Access values via: oscMessage.Values[0], oscMessage.Values[1], etc
public void AllMessageHandler (OscMessage oscMessage)
{
// something like this below
object msgValueOne = oscMessage.Values[0];
//depends what you are receiving and the next conversion
string FirstMsg = msgValueOne.ToString ();
Debug.Log(FirstMsg);
}
@beatsaway
Copy link

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment