What I need to do is get foreach values from one method called private void ReceiveData() and send them to another method void Update() . How to do that in c#?
private void ReceiveData()
{
IPEndPoint remoteIP = new IPEndPoint(IPAddress.Parse("10.0.2.217"), port);
client = new UdpClient(remoteIP);
while (true)
{
try
{
IPEndPoint anyIP = new IPEndPoint(IPAddress.Any, 0);
data = client.Receive(ref anyIP);
int nIndex = 0;
foreach(SignalIndex si in xmlreader.cdpSignals)
{
x= ReadSingleBigEndian(data, si.index + 0);
y= ReadSingleBigEndian(data, si.index + 4);
z= ReadSingleBigEndian(data, si.index + 8);
alpha= ReadSingleBigEndian(data, si.index + 12);
theta= ReadSingleBigEndian(data, si.index + 16);
phi= ReadSingleBigEndian(data, si.index + 20);
// xmlreader.unityGameObjects[nIndex].transform.localPosition = new Vector3(x,y,z);
// xmlreader.unityGameObjects[nIndex].transform.Rotate(alpha,theta,phi);
}
}
catch (Exception err)
{
print(err.ToString());
}
}
client.Close();
}
void Update()
{
foreach(GameObject go in xmlreader.unityGameObjects)
{
go.transform.localPosition = new Vector3(x,y,z);
go.transform.transform.Rotate(alpha,theta,phi);
}
}
There are 2 methods and I need to get the values in foreach from ReceiveData() and instantiate them in method Update(). All variables in foreach from ReceiveData() are public, but they all takes 0 in Update().
EDIT 2:
Documentation for ReaderWriterLockSlim: http://msdn.microsoft.com/en-us/library/system.threading.readerwriterlockslim.aspx