无法使用跳跃式手指破坏物体

Cannot destroy object using leap motion fingers

大家好。我在检测手指与物体的碰撞时遇到了一点问题。在我的第一阶段,当对象与我的手指碰撞时,我的代码在这里:

DetectionCollision.cs

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

public class GetFlashLight : MonoBehaviour {

// Use this for initialization
void Start () {

}

private HandModel IsHand(Collider other){
    if (other.transform.parent && other.transform.parent.parent && other.transform.parent.parent.GetComponent<HandModel> ()) {
        return other.transform.parent.parent.parent.GetComponent<HandModel> ();
    } else {
        return null;
    }
}


void OnTriggerEnter(Collider other) {
    HandModel hand_model = IsHand (other);
    if (hand_model != null) {
        this.GetComponent<DisableObject> ().enabled = true;
    } else {
        this.GetComponent<DisableObject> ().enabled = false;
    }
}
}

DisableObject.cs

 public GameObject TurnOnFlashLight;
  // Use this for initialization
 void Start () {
    TurnOnFlashLight.gameObject.SetActive (true);
 }

问题是当我应用相同的代码但不同的 C# 脚本时(当然) 它没有用。您认为问题出在哪里?

您可以尝试以下方法来尝试查找另一个对撞机是否有手:

如果您希望对搜索过程进行微调,或者 GetComponentInParent 限制对您来说是个障碍,那么第二个版本会放在这里。

using UnityEngine;

internal class HandModel : MonoBehaviour
{
}

internal class MyClass : MonoBehaviour
{
    private HandModel TryGetHandVersion1(Collider other)
    {
        return other.GetComponentInParent<HandModel>();
    }

    private HandModel TryGetHandVersion2(Collider other)
    {
        var current = other.transform;
        while (current != null)
        {
            var handModel = current.GetComponent<HandModel>();
            if (handModel != null)
                return handModel;

            current = current.parent;
        }
        return null;
    }

    private void OnTriggerEnter(Collider other)
    {
        var isHand = TryGetHandVersion1(other) != null;
    }
}
using UnityEngine;
using Leap;
using Leap.Unity;

void OnTriggerEnter(Collider other){
   FingerModel finger = other.GetComponentInParent<FingerModel>();
    if(finger){
        this.GetComponent<DisableObject> ().enabled = true;
    }
}

通过这样做,我得到了我想要的。