目前我正在使用 Unity 和虚拟现实工具包 (VRTK) 进行项目。我想记录抓取对象的时间(用户抓取对象的时间)。
到目前为止,我得到了这个:
using System;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using VRTK;
public class System_2_Script_Slider_X : MonoBehaviour
{
float Timer;
void Start()
{
Timer = 0;
if (GetComponent<VRTK_InteractableObject>() == null)
{
Debug.LogError("Team3_Interactable_Object_Extension is required to be attached to an Object that has the VRTK_InteractableObject script attached to it");
return;
}
GetComponent<VRTK_InteractableObject>().InteractableObjectGrabbed += new InteractableObjectEventHandler(ObjectGrabbed);
GetComponent<VRTK_InteractableObject>().InteractableObjectUngrabbed += new InteractableObjectEventHandler(ObjectUngrabbed);
}
private void ObjectGrabbed(object sender, InteractableObjectEventArgs e)
{
//Some Code
Timer += Time.deltaTime;
}
private void ObjectUngrabbed(object sender, InteractableObjectEventArgs e)
{
//Some Code
File.AppendAllText("PATH/Timer.txt", Timer.ToString());
Timer = 0;
}
}
不幸的是,这不起作用,因为我得到了大约 2 毫秒的时间,即使我抓住物体的时间更长。因此,该ObjectGrabbed()
功能似乎启动了计时器,但立即停止了它。
我怎样才能解决这个问题?