Set a cursor hand controlled with Kinect SDK

Hello,

I’m developping a basic application to load and modify molecules and my main goal is to implement Kinect to do it.
So far I’ve been able to do it with a mouse and I would like to do it with my right hand.
After searching for a while I tried to define my cursor in a screen environment like if it would be done with a mouse (Input.mousePosition.x) substituting this for the hands coordinates (normalized for the screen dimensions).
I can’t make the cursor follow my hand, but I can make a game object follow any part of my body so my coordinates are being imported and when I debug my control variables they return a value contained in the screen dimensions.
I guess my error is in OnGUI().
Can anybody help me.

Thanks in advance.

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
public class handPointer_01 : MonoBehaviour
{
    public Texture2D cursorImage_00;
    public Texture2D cursorImage_01;
    public Texture2D cursorImage_02;
    private Texture2D cursorImage;
    private int cursorWidth = 16;
    private int cursorHeight = 16;
    private string defaultResource = "MousePointer";
    private GameObject target;
   
    public GameObject leftHandPos;
    public GameObject rightHandPos;
    public GameObject leftShoulderPos;
    public GameObject rightShoulderPos;
    public GameObject leftHipPos;
    public GameObject rightHipPos;
   
    private float RightHandX;
    private float RightHandY;
    private float xPrevious;
    private float yPrevious;
    private double MoveThreshold = 0.01;
    void Start()
    {
        //Switch off default cursor
       
        if(!cursorImage_00 || !cursorImage_01 || !cursorImage_02)
        {
            cursorImage = (Texture2D) Resources.Load(defaultResource);
            Debug.Log(cursorImage);
        }
        else Cursor.visible = false;
        //cursorImage = (Texture2D) Instantiate(cursorImage);
    }
    void Update()
    {
       
        if (rightShoulderPos.transform.position.z - rightHandPos.transform.position.z > 0.01)
        {
            float xScaled = Mathf.Abs((rightHandPos.transform.position.x - rightShoulderPos.transform.position.x) / ((rightShoulderPos.transform.position.x - leftShoulderPos.transform.position.x) * 2)) * Screen.width;
            float yScaled = Mathf.Abs((rightHandPos.transform.position.y - rightHipPos.transform.position.y) / ((rightShoulderPos.transform.position.y - rightHipPos.transform.position.y) * 2)) * Screen.height;

            // the hand has moved enough to update screen position (jitter control / smoothing)
            if (Mathf.Abs(rightHandPos.transform.position.x - xPrevious) > MoveThreshold || Mathf.Abs(rightHandPos.transform.position.y - yPrevious) > MoveThreshold)
            {
                RightHandX = Mathf.Min(Mathf.Max(xScaled,Screen.width),0);
                RightHandY = Mathf.Min(Mathf.Max(yScaled,Screen.height),0);

                xPrevious = rightHandPos.transform.position.x;
                yPrevious = rightHandPos.transform.position.y;
               
                // reset the tracking timer
                //trackingTimerCounter = 10;
            }
        }
       
        // // Get the left mouse button
        // if(Input.GetMouseButtonDown(0))
        // {           
            // RaycastHit hitInfo;
            // target = GetClickedObject (out hitInfo);
       
            // if (target != null && target.gameObject.tag =="Draggable")
            // {
                // cursorImage = cursorImage_02;
                // Debug.Log("Hit");
            // }
            // else
            // {
                // cursorImage = cursorImage_01;
                // Debug.Log("Miss");
            // }
        // }
       
        // // Disable movements on button release
        // if (!Input.GetMouseButton(0))
        // {
            // cursorImage = cursorImage_00;
        // }
        cursorImage = cursorImage_00;
    }

    void OnGUI()
    {
            //GUI.DrawTexture(new Rect(Input.mousePosition.x, Screen.height - Input.mousePosition.y, cursorWidth, cursorHeight), cursorImage);
            GUI.DrawTexture(new Rect(RightHandX ,RightHandY , cursorWidth, cursorHeight), cursorImage);
    }
   
    GameObject GetClickedObject (out RaycastHit hit)
    {
        GameObject target = null;
        Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
        if (Physics.Raycast (ray.origin, ray.direction * 10, out hit)) {
            target = hit.collider.gameObject;
        }
        return target;
    }

}

Not sure if i could help you but sounds interesting. You might want to wait till Facebook figures out what it is going to do for user input. You could make it work for the Connect but will be outdated when Facebook reviles there new user input system in Q1 2016. I know there are some interesting things in the works - Like this:

Also this:

Which Facebook just bought a couple weeks back.