[英]How to let script know that a GameObject is grabbed in unity 3d
我正在使用 SteamVR 开发一个 VR 项目,当使用控制器抓取游戏对象时,我需要特定事件(粒子系统)启动它似乎总是如此)
private Interactable interactable;
public bool isGrabbed=false;
// Use this for initialization
void Start()
{
interactable = this.GetComponent<Interactable>();
}
// Update is called once per frame
void Update()
{
if (interactable != null )
{
isGrabbed = true;
}
}
transform.GetComponent<OVRGrabbable>().isGrabbed
您需要检查它是否附在手上:
if (interactable != null && interactable.attachedToHand != null) { ... }
您在这里检查的是 Component interactable
是否存在 -> Checking if it is not null
。 当然,如果你没有删除它,它是存在的。
您可能应该使用的是提供的Throwable
类或其他类之一。 查看 SteamVR/InteractionSystem 文件夹中的演示场景,因为它不久前更新过,现在功能更强大。
根据您的需要,您应该检查弓或任何您找到的东西。 如果名为“SteamVR Unity Plugin - Input System.pdf”的 SteamVR 文件夹包含文档,则还有一个文档 pdf。
祝你好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.