首页 > 解决方案 > 如何在 Hololens 上获得手的位置?

问题描述

我有这个脚本是为了用 hololens 获得手的位置,但它不起作用,它给了我这个错误:Errore CS0123 Nessun 过载 per 'GetPosition' corrisponde al delegato 'Action' 有人可以帮我吗?

这是代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.WSA.Input;


public class Hand : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }



    void Awake()
    {

        InteractionManager.InteractionSourcePressed += GetPosition; // No overload for 'GetPosition' corresponds to delegate 'Action<InteractionSourcePressedEventArgs>'

    }

    private void GetPosition(InteractionSourceState state)
    {
        Vector3 pos;
        if (state.sourcePose.TryGetPosition(out pos))
        {
            Debug.Log(pos);
        }
    }
}

标签: positionhololens

解决方案


错误代码指出,如果要注册InteractionSourcePressed输入事件,则应修改回调函数GetPosition以匹配InteractionSourcePressed事件的委托。

因此,在这种情况下,您可以参考以下代码来解决此问题:

private void GetPosition(InteractionSourceState state)

=>

private void GetPosition(InteractionSourcePressedEventArgs args)

更多信息请参阅:Windows 特定 API (XR.WSA.Input)


推荐阅读