UnityException: get_transform can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
当使用Unity SDK API时,是不允许在子线程中调用的。
如果你使用了HP-Soket实现的网络通讯,它是在异步线程接收消息的,所以不能直接在此处处理角色的移动、旋转等操作。
为了解决这个问题,你可以将接收到的消息放入一个队列(Queue)中。
由于HP-Soket脚本的Update函数是在主线程下调用的,你可以在Update函数中弹出消息队列,就可以直接调用Unity的API来处理相应的操作了。