2017-12-01 14 views
0

사용자가 지정된 개체를보고 두 지점 사이를 이동하는 스크립트를 작성했습니다. 특히 광선을 사용하여 두 객체 중 하나가 화면 중앙에 있는지 확인합니다. 표준 FPSController (메인 카메라 아래에 위치) 및 마우스 컨트롤과 함께 작동합니다. VR 지원을 활성화하면 감지가 작동을 멈 춥니 다 (중심점뿐만 아니라 전체 디스플레이에 대해). Oculus가 마우스와 동일한 방식으로 작동하도록 스크립트에 추가해야하는 것은 무엇입니까?Unity에서 HMD와 함께 작동하도록 RaycastHit을 얻으려면 어떻게해야합니까?

이 코드는 이름으로 물체를 감지 한 후 태그에 의해 할당 된 객체에 순간 이동으로 작동합니다

using UnityEngine; 
using System.Collections; 
using UnityEngine.VR; 

public class lookTeleport : MonoBehaviour 
{ 
    public GameObject destination; 
    public Transform target; 
    RaycastHit hit; 
    Ray ray; 

    void Start() 
    { 
     Cursor.lockState = CursorLockMode.Locked; 
    } 

    void Update() 
    { 
     ray = Camera.main.ScreenPointToRay(Input.mousePosition); //mouse control 
     if (Physics.Raycast(ray, out hit)) 
     { 
      if (hit.collider.gameObject.name == "teleporterA") 
      { 
       //Debug.Log("teleporter A detected"); 
       destination = GameObject.FindWithTag("teleportY"); 
       transform.position = destination.transform.position; 
      } 
      if (hit.collider.gameObject.name == "teleporterB") 
      { 
       //Debug.Log("teleporter B detected"); 
       destination = GameObject.FindWithTag("teleportX"); 
       transform.position = destination.transform.position; 
      } 
     } 
    } 
} 

나는 내가 VR 동등한와 Input.MousePosition 교체에보고해야합니다 생각합니다. 당신이 VR에 있고, 마우스를 사용하지 않을의 Input.mousePosition가에서 선을 캐스팅하는 화면 포인트로 사용할 수 없기 때문에 당신 대신 당신의 중간을 사용할 수, ray = Camera.main.ScreenPointToRay(new Vector2(Screen.height/2, Screen.width/2));
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
를 교체해야

답변

0

사용자가 보는 화면 (십자형 모양)