//-----------------------------------------------------------------------------
    // destroys the avatar and refreshes the list of avatar controllers
    private void DestroyUserAvatar(GameObject avatarObj)
    {
        if (avatarObj)
        {
            Destroy(avatarObj);
            if (mKinectManager)
            {
                // refresh the KM-list of available avatar controllers
                MonoBehaviour[] monoScripts = FindObjectsOfType(typeof(MonoBehaviour)) as MonoBehaviour[];
                mKinectManager.avatarControllers.Clear();

                foreach (MonoBehaviour monoScript in monoScripts)
                {
                    if ((monoScript is AvatarController2D) && monoScript.enabled)
                    {
                        AvatarController2D avatar = (AvatarController2D)monoScript;
                        mKinectManager.avatarControllers.Add(avatar);
                    }
                }
            }
        }
    }
    //-----------------------------------------------------------------------------
    // creates avatar for the given user
    private GameObject CreateUserAvatar(long userId, int userIndex)
    {
        GameObject avatarObj         = null;
        GameObject userLocatorObject = null;

        if (avatarModels.Length > 0)
        {
            Vector3 userPos = new Vector3(0, 1, 0);
            //Quaternion userRot = Quaternion.Euler(!mirroredMovement ? Vector3.zero : new Vector3(0, 180, 0));
            Quaternion userRot = Quaternion.Euler(new Vector3(0, 180, 0));

            // create random avatar
            int        randomModelIndex = Random.Range(0, avatarModels.Length);
            GameObject avatarModel      = avatarModels[randomModelIndex];

            // create the locator object

            Debug.Log("Setting avatar index to: " + randomModelIndex);

            //userLocatorObject = addUserLocator(userId, Vector3.zero);
            avatarObj      = Instantiate(avatarModel, userPos, userRot);
            avatarObj.name = "User-" + userId;

            AvatarController2D ac = avatarObj.GetComponent <AvatarController2D>();
            if (ac != null)
            {
                //ac = avatarObj.AddComponent<AvatarController>();
                //ac = avatarObj.AddComponent<AvatarController2D>();
                ac.playerIndex = userIndex;

                ac.smoothFactor        = smoothFactor;
                ac.posRelativeToCamera = posRelativeToCamera;

                ac.mirroredMovement = mirroredMovement;
                ac.verticalMovement = verticalMovement;

                ac.groundedFeet      = groundedFeet;
                ac.applyMuscleLimits = applyMuscleLimits;

                //set offset node
                //ac.offsetNode = userLocatorObject;

                // start the avatar controller
                ac.SuccessfulCalibration(userId, false);
            }



            // refresh the KM-list of available avatar controllers
            MonoBehaviour[] monoScripts = FindObjectsOfType(typeof(MonoBehaviour)) as MonoBehaviour[];
            mKinectManager.avatarControllers.Clear();

            foreach (MonoBehaviour monoScript in monoScripts)
            {
                if ((monoScript is AvatarController2D) && monoScript.enabled)
                {
                    AvatarController2D avatar = (AvatarController2D)monoScript;
                    mKinectManager.avatarControllers.Add(avatar);
                }
            }
        }

        return(avatarObj);
    }