How to use UDP with Unity methods
<p>I created a Cube object and attached this script.</p>

<pre><code>using UnityEngine;
using System.Collections;

public class CubeMove : MonoBehaviour {
    void Start () {
    }

    void Update () {
    }

    public void Move () {
        Vector3 moveVector = new Vector3(10, 0, 0);
        transform.Translate(moveVector);
    }
}
</code></pre>

<p>I wanted to use UDP to control cube move, so I created UDPManager.</p>

<pre><code>using UnityEngine;
using System.Collections;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;

public class UDPManager : MonoBehaviour
{
    static UdpClient udp;
    Thread thread;

    public GameObject cube;
    public CubeMove cubemove;

    void Start ()
    {
        udp = new UdpClient(12345);
        cubemove = cube.GetComponent&lt;CubeMove&gt;();
        thread = new Thread(new ThreadStart(ThreadMethod));
        thread.Start();
    }

    void Update ()
    {
    }

    void OnApplicationQuit()
    {
        udp.Close();
        thread.Abort();
    }

    private void ThreadMethod()
    {
        while(true)
        {
            IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);

            byte[] receiveBytes = udp.Receive(ref RemoteIpEndPoint); 
            string returnData = Encoding.ASCII.GetString(receiveBytes);
            Debug.Log(returnData);
            if (returnData == "1\n") {
                cube.SendMessage ("Move");
                // or
                cubemove.Move();

            }
        }
    } 
}
</code></pre>

<p>but these doesn't works with below errors.</p>

<pre><code>- SendMessage can only be called from the main thread.
- get_transform can only be called from the main thread.
</code></pre>

<p>Can I call unity methods when I receive udp command?</p>