Search Unity

Argument Out Of Range Exception error + Leap Motion

Discussion in 'Scripting' started by mayank_chaurasia, Jan 21, 2018.

  1. mayank_chaurasia

    mayank_chaurasia

    Joined:
    Nov 10, 2016
    Posts:
    4
    Hi I m new to unity C# coding i had taken help of Leap Motion tutorial to move the camera in and out according to the hand gesture but it is giving me
    ArgumentOutOfRangeException : Argument is out of range.
    Parameter name: index


    code is below

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using Leap;
    using Leap.Unity;

    public class ControlMove : MonoBehaviour {

    Controller controller;
    float HandPalmPitch;
    float HandPalmYam;
    float HandPalmRoll;
    float HandWristRot;

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {
    controller = new Controller ();
    Frame frame = controller.Frame ();
    List<Hand> hands = frame.Hands;
    if (frame.Hands.Count > 0) {
    Hand fristhand = hands [0];
    }

    HandPalmPitch = hands [0].PalmNormal.Pitch;
    HandPalmRoll = hands [0].PalmNormal.Roll;
    HandPalmYam = hands [0].PalmNormal.Yaw;

    HandWristRot = hands [0].WristPosition.Pitch;

    Debug.Log ("Pitch :" + HandPalmPitch);
    Debug.Log ("Roll :" + HandPalmRoll);
    Debug.Log ("Yam :" + HandPalmYam);

    //Move Object

    if (HandPalmYam > -2f && HandPalmYam < 3.5f) {
    transform.Translate (new Vector3 (0, 0, 1 * Time.deltaTime));
    } else if (HandPalmYam < -2.2f) {
    transform.Translate (new Vector3 (0, 0, -1 * Time.deltaTime));
    }
    }
    }
     
  2. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    Use Code Tags as described in this post, which is stickied at the top of every forum here.

    Do not create multiple threads for the same problem.
     
  3. rtanwar616

    rtanwar616

    Joined:
    Feb 5, 2018
    Posts:
    3
    id you get the fix for this ?
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    There is a 'fix' in the linked thread. Your code is probably different. In the future, please lookup errors and/or post your own thread if you have an issue. :)
     
  5. rtanwar616

    rtanwar616

    Joined:
    Feb 5, 2018
    Posts:
    3
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using Leap;
    using Leap.Unity;
    public class iliketomoveit : MonoBehaviour {

    Controller controller;
    float HandPalmPitch;
    float HandPalmYam;
    float HandPalmRoll;
    float HandWristRot;
    void Start () {

    }

    // Update is called once per frame
    void Update () {
    controller = new Controller();
    Frame frame = controller.Frame();
    List<Hand> hands = frame.Hands;
    if (frame.Hands.Count > 0)
    {
    Hand fristHand = hands[0];
    }
    HandPalmPitch = hands[0].PalmNormal.Pitch;
    HandPalmRoll = hands[0].PalmNormal.Roll;
    HandPalmYam = hands[0].PalmNormal.Yaw;
    HandWristRot = hands[0].WristPosition.Pitch;
    Debug.Log("Pitch :" + HandPalmPitch);
    Debug.Log("Roll :" + HandPalmRoll);
    Debug.Log("Yam :" + HandPalmYam);
    if (HandPalmYam > -2f && HandPalmYam < 3.5f)
    {
    transform.Translate ( new Vector3(0, 0,1 * Time.deltaTime));
    }else if (HandPalmYam < -2.2f)
    {
    transform.Translate ( new Vector3(0, 0, -1 * Time.deltaTime));

    }
    }
    }


    this is the code and the image is the error . can you give me the updated code with the 'fix' ?
     

    Attached Files:

  6. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    374
    Your frame.Hands is empty, therefor there is no item at index 0.