public void StartFeed(MemoryBridge memoryBridge, string fileName)
    {
        meshRenderer = GetComponent <MeshRenderer>();

        this.memoryBridge = memoryBridge;
        this.fileName     = fileName;

        memoryBridge.SetVector3("CamLocalPos" + fileName + memoryBridge.cameraFeeds.Count, Vector3.zero);
        memoryBridge.SetVector3("CamLocalEuler" + fileName + memoryBridge.cameraFeeds.Count, Vector3.zero);

        //meshRenderer.material.SetTexture("_MainTex", readTex);
    }
    public GameObject CalculateTarget()
    {
        var worldVertPositions = new List <Vector3>();
        var offsets            = new List <Vector3>();
        var childFilters       = GetComponentsInChildren <MeshFilter>();

        foreach (var meshFilter in childFilters)
        {
            var vertices = meshFilter.mesh.vertices;
            foreach (var vertex in vertices)
            {
                var worldPos = meshFilter.transform.TransformPoint(vertex);
                worldVertPositions.Add(worldPos);
            }
            //meshFilter.gameObject.SetActive(false);
        }
        foreach (var worldPos in worldVertPositions)
        {
            var offset = transform.InverseTransformPoint(worldPos);
            offsets.Add(offset);
        }
        float   furthestY  = 0;
        Vector3 footOffset = Vector3.zero;

        for (int i = 0; i < offsets.Count; i++)
        {
            if (offsets[i].y > furthestY)
            {
                furthestY  = offsets[i].y;
                footOffset = offsets[i];
            }
        }
        var foot = Instantiate(Resources.Load("Foot", typeof(GameObject))) as GameObject;

        foot.transform.SetParent(transform);
        foot.GetComponent <MeshRenderer>().material.color = color;
        // footOffset.y = -footOffset.y;
        foot.transform.localPosition = footOffset;

        memoryBridge.SetVector3(servoName + "contactPoint", footOffset);

        targetOffset = (float)(Math.Atan2(footOffset.z, footOffset.y));

        targetOffset *= (float)(180 / Math.PI);
        //targetOffset = Vector3.Angle(transform.position, foot.transform.position);
        // Debug.Log("target offset " + targetOffset);

        var footRenderer = foot.GetComponent <LineRenderer>();

        footRenderer.SetPosition(0, Vector3.zero);
        var wristOffset = foot.transform.InverseTransformPoint(transform.position);

        footRenderer.SetPosition(1, wristOffset);
        footRenderer.material.color = color;

        //  limbLength = Vector3.Distance(transform.position, foot.transform.position);
        groundPoint = foot.transform;
        return(foot);
    }
    void Update()
    {
        if (!receivingResponce) //IS THE CLIENT RESPONDING
        {
            Debug.Log("client file empty");
            //camFeedFile = MemoryMappedFile.Create(MapProtection.PageReadWrite, textureByte.Length, "CamFeedFile" + fileName + this.memoryBridge.cameraFeeds.Count);
            camFeedFile = MemoryMappedFile.Open(MapAccess.FileMapAllAccess, "CamFeedFile" + fileName + memoryBridge.cameraFeeds.Count);

            if (camFeedFile != null)
            {
                _receivingResponce = true;
                BuildCamera();
            }
        }
        else
        {
            Debug.Log("cam feed update");
            memoryBridge.SetVector3("CamLocalPos" + fileName + memoryBridge.cameraFeeds.Count, cameraRig.localPosition);
            memoryBridge.SetVector3("CamLocalEuler" + fileName + memoryBridge.cameraFeeds.Count, cameraRig.localEulerAngles);
            /////WORKS////
            using (Stream camStream = camFeedFile.MapView(MapAccess.FileMapAllAccess, 0, feedByteCount))
            {
                byte[] buffer = new byte[feedByteCount];
                using (MemoryStream ms = new MemoryStream())
                {
                    int read;
                    while ((read = camStream.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        ms.Write(buffer, 0, read);
                    }
                    var byteArray = ms.ToArray();
                    readTex.LoadRawTextureData(byteArray);
                }
            }
            readTex.Apply();
            meshRenderer.material.SetTexture("_MainTex", readTex);
        }
    }