Paul Kevin Paul Kevin - 7 days ago 5
C# Question

Cannot implicitly convert type `System.Collections.Generic.List<Leap.Hand>` to `Leap.Hand`

I've got this error
Cannot implicitly convert type

System.Collections.Generic.List<Leap.Hand>
to
Leap.Hand


Here's my code:

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

public class Swimming : MonoBehaviour {

Controller controller;


void Start(){
controller = new Controller ();
}

void Update(){

Frame frame = controller.Frame (); // controller is a Controller object
Hand hand = frame.Hands;

for (int i = 0; i < frame.Hands.Count; i++) {
if (frame.Hands [i].IsLeft) {
Debug.Log ("Left Hand Detected");
}
}
}
}


I've searched a lot but i couldn't find something. Can anyone help me please

Answer

Your problem is here:

Hand hand = frame.Hands;

frame.Hands is a collection of Hand, but you're trying to assign this value to a single instance of Hand. So, instead, you should be doing this:

List<Hand> hands = frame.Hands;