using System.Net; using
System.Collections; using UnityEngine;
using Rug.Osc;public class OscSendControler :
Singleton { //
Sender Instance private OscSender
m_Sender;public OscSender Sender { get {
return m_Sender; } }[InspectorNoteAttribute(“Osc”, “Port
to send to”)] public int RemotePort =
5000;[InspectorNoteAttribute(“Osc”, “IP
Address to send to”)] public string
RemoteAddress = “127.0.0.1”; //Adress
of the Processingprotected OscSendControler() { }
// Use this for initialization void
Start () {
// Log the start Debug.Log (“Starting Osc”);
// Ensure that the sender is disconnected Disconnect ();
// The address to send to IPAddress addess = IPAddress.Parse
(RemoteAddress);
// The port to send to int port = RemotePort;
// Create an instance of the sender m_Sender = new
OscSender(addess, port);
// Connect the sender m_Sender.Connect ();
// We are now connected Debug.Log (“Sender Connected”); }
// Update is called once per frame
void Update () {} // OnDestroy is called when the
object is destroyed public override
void OnDestroy () { Disconnect ();base.OnDestroy (); } privatevoid Disconnect () {
// If the sender exists if (m_Sender != null) {
// Disconnect the sender Debug.Log (“Disconnecting Sender”);m_Sender.Dispose (); // Nullifiy the sender m_Sender = null; } }public static void sendYellow(){
OscSendControler.m_Sender.Write(“y”);
}public static void sendGreen(){
OscSendControler.m_Sender.Write(“g”);
//sp.Write("
"); }public static void sendRed(){
OscSendControler.m_Sender.Write(“r”);
}}
Your problem is that ‘m_Sender’ is not static and therefore you will have a different instance of the variable for each instance of the class. But the functions you use to access m_Sender’ are static. They both (variable and functions) need to be either static or not static.
For future posts, use the 101/010 button for formatting your code, not the quote button.