我是团结三维编程的初学者,我有一个项目将我的反馈设备与虚拟现实软件(unity3d免费版)集成。我使用跳跃动作让我的手出现在unity3d上,当物体(球)碰到手时,它会触发反馈设备发送信息。
我为我的反馈设备构建了dll库,我已经尝试过c#并且正在工作。
我使用onCollisionEnter来触发事件。这是我的剧本:
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
public class trigger : MonoBehaviour {
[DllImport("tensLibs.dll", EntryPoint="tens_init")]
public static extern int tens_init ([MarshalAsAttribute(UnmanagedType.LPStr)]string port);
[DllImport("tensLibs.dll", EntryPoint = "tens_shutdown")]
public static extern void tens_shutdown();
[DllImport("tensLibs.dll", EntryPoint = "tens_settarget")]
public static extern int tens_settarget(byte id);
[DllImport("tensLibs.dll", EntryPoint = "tens_write")]
public static extern int tens_write([MarshalAsAttribute(UnmanagedType.LPStr)]string buf, int count);
[DllImport("tensLibs.dll", EntryPoint = "tens_enable")]
public static extern int tens_enable(byte supply_on, byte bridge_on);
[DllImport("tensLibs.dll", EntryPoint = "tens_power")]
public static extern int tens_power(byte power);
[DllImport("tensLibs.dll", EntryPoint = "tens_freq")]
public static extern int tens_freq(byte freq);
[DllImport("tensLibs.dll", EntryPoint = "tens_chargerate")]
public static extern int tens_chargerate(byte rate);
[DllImport("tensLibs.dll", EntryPoint = "tens_writeconfig")]
public static extern int tens_writeconfig();
[DllImport("tensLibs.dll", EntryPoint = "tens_envs")]
public static extern int tens_envs(byte distance);
void OnCollisionEnter (Collision col) {
if (col.gameObject.name == "bone1" || col.gameObject.name == "bone2" || col.gameObject.name == "bone3" || col.gameObject.name == "palm") {
if (tens_init("COM8") == 1){
Debug.Log ("Com 8 is initiated"); }
else {
Debug.Log ("Com 8 does not exists"); }
tens_settarget(0); //send to device 0
System.Threading.Thread.Sleep(10);
tens_envs(150); //send value
System.Threading.Thread.Sleep(10);
tens_shutdown(); //close the com
}
}
问题是,当我触摸球时,事件只是通过显示Com 8 is initiated
向我显示tens_init正在工作,但程序的其余部分未执行(我认为因为不起作用)。
我是否错误地使用了脚本?
谢谢。答案 0 :(得分:0)
在统一中你不使用System.Threading.Thread.Sleep(...)
语法,你需要研究yield waitforseconds