C# 无法使用跳跃运动手指销毁对象
大家好。我在检测手指与物体的碰撞时有点小问题。在我的第一阶段,当物体与我的手指碰撞时,我销毁它的代码如下: 检测碰撞.csC# 无法使用跳跃运动手指销毁对象,c#,unity3d,leap-motion,C#,Unity3d,Leap Motion,大家好。我在检测手指与物体的碰撞时有点小问题。在我的第一阶段,当物体与我的手指碰撞时,我销毁它的代码如下: 检测碰撞.cs using UnityEngine; using System.Collections; using Leap; using Leap.Unity; public class GetFlashLight : MonoBehaviour { // Use this for initialization void Start () { } private HandMod
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;
}
}
}
public GameObject TurnOnFlashLight;
// Use this for initialization
void Start () {
TurnOnFlashLight.gameObject.SetActive (true);
}
问题是当我应用相同的代码但不同的c#脚本时(当然)
它不起作用。你认为问题是什么
您可以尝试以下操作,以确定另一台对撞机是否有手: 第二个版本是放在这里,如果你喜欢微调搜索过程或限制是一个阻碍你
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;
}
}
使用UnityEngine;
内部类模型:单行为
{
}
内部类MyClass:MonoBehavior
{
私人手持模型TryGetHandVersion1(对撞机其他)
{
返回other.getComponentParent();
}
私人手持模型TryGetHandVersion2(其他对撞机)
{
无功电流=其他变换;
while(当前!=null)
{
var handModel=current.GetComponent();
if(handModel!=null)
回归模型;
current=current.parent;
}
返回null;
}
专用空对撞机(对撞机其他)
{
var isHand=TryGetHandVersion1(其他)!=null;
}
}
使用UnityEngine;
使用Leap;
运用跳跃、统一;
无效对撞机(对撞机其他){
FingerModel finger=other.getComponentParent();
如果(手指){
this.GetComponent().enabled=true;
}
}
通过这样做,我得到了我想要的。这不起作用。但是谢谢你的回复,我会把我得到的贴出来
using UnityEngine;
using Leap;
using Leap.Unity;
void OnTriggerEnter(Collider other){
FingerModel finger = other.GetComponentInParent<FingerModel>();
if(finger){
this.GetComponent<DisableObject> ().enabled = true;
}
}