一、将VRTK_SimplePointer脚本中pointerCollidedWith变量改为全局变量
Paste_Image.png
二、物体设置Tag值,为了判断是否是要拖拽的物体(代码如下)
Paste_Image.png
/// <summary>
/// 射线拖拽改变模型位置
/// </summary>
public void RayDragObj(RaycastHit m_RaycastHit)
{
if (m_RaycastHit.collider != null && m_RaycastHit.collider.tag == "Player")
{
var device = SteamVR_Controller.Input((int)controllerIndex);
if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger))
{
if (m_RaycastHit.collider.gameObject.GetComponent<Rigidbody>() == null)
{
m_RaycastHit.collider.gameObject.AddComponent<Rigidbody>();
m_RaycastHit.collider.gameObject.GetComponent<Rigidbody>().useGravity = false;
}
pointerCollidedWith.transform.SetParent(this.transform);
}
if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger))
{
pointerCollidedWith.transform.SetParent(null);
}
}
}
三、所有要修改的内容都是在VRTK_SimplePointer这个脚本中修改的
网友评论