项目:增强游戏(vuforia)
我有一个飞机可以住球。
飞机上有刚体和网状对撞机。 球上有一个球体碰撞器和刚体,并打开了重力。
在我玩游戏时,球从飞机上掉下来并不断掉下。
我希望球保持在飞机上,以便我可以通过触摸输入来控制它。
答案 0 :(得分:0)
我遇到了这个问题,我使用I TrackableEventHandler
解决了。
查看以下脚本:
using System.Collections;
using UnityEngine;
using Vuforia;
public class MarkerController: MonoBehaviour, ITrackableEventHandler
{
private TrackableBehaviour mTrackableBehavior;
// Start is called before the first frame update
void Start()
{
mTrackableBehavior = GetComponent<TrackableBehaviour>();
if (mTrackableBehavior)
{
mTrackableBehavior.RegisterTrackableEventHandler(this);
}
}
public void OnTrackableStateChanged(TrackableBehaviour.Status previousStatus, TrackableBehaviour.Status newStatus)
{
if(newStatus == TrackableBehaviour.Status.DETECTED || newStatus == TrackableBehaviour.Status.TRACKED || newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
{
OnTrackingFound();
} else
{
OnTrackingLost();
}
}
private void OnTrackingFound()
{
Renderer[] rendererComponents = GetComponentsInChildren<Renderer>();
Collider[] colliderComponents = GetComponentsInChildren<Collider>();
for (int i = 0; i < this.transform.GetChildCount(); i++)
{
Debug.Log("Activating the children");
this.transform.GetChild(i).gameObject.SetActive(true);
}
foreach(Renderer component in rendererComponents)
{
component.enabled = true;
}
foreach(Collider component in colliderComponents)
{
component.enabled = true;
}
Debug.Log("Tracking of " + mTrackableBehavior.TrackableName + " found");
}
private void OnTrackingLost()
{
Renderer[] rendererComponents = GetComponentsInChildren<Renderer>();
Collider[] colliderComponents = GetComponentsInChildren<Collider>();
for (int i = 0; i < this.transform.GetChildCount(); i++)
{
Debug.Log("Deactivating children");
this.transform.GetChild(i).gameObject.SetActive(false);
}
foreach (Renderer component in rendererComponents)
{
component.enabled = false;
}
foreach (Collider component in colliderComponents)
{
component.enabled = false;
}
Debug.Log("Tracking of " + mTrackableBehavior.TrackableName + " lost");
}
}
在本课程中,我仅在找到标记的跟踪时才激活组件!否则,它将被停用,并且当再次找到跟踪时,它将以丢失跟踪之前的状态显示。
我已将此脚本添加到ARCamera组件。在这里工作正常!