GVRTeleport 스크립트를 사용하여 카드 보드 앱으로 순간 이동을 허용합니다. 순간 이동을위한 레이 캐스트가 한 레이어를 제외한 모든 것을 무시하기를 바랍니다. this 페이지로 이동합니다. 사과 (사과,이 코드의 소유자에게 원래 링크를 찾을 수 없음)를 수정했지만 현재 텔레포트 스크립트는 아무 것도 볼 수 없습니다. 어떤 아이디어? 내 층 레이어는 레이어 8입니다.이 레이어는 내가이 레이 캐스트와 상호 작용하기를 원합니다.Unity의 특정 레이어에 레이 캐스트
using UnityEngine;
public class GVRTeleport : MonoBehaviour {
public float viewHeight = 7f;
Vector3 fwd;
public float maxDistance = 10f;
public LineRenderer line;
public GameObject parent;
public GameObject targetIndicator;
public StraightLineParam genLine;
int layerMask = 1 << 8;
void Start() {
}
void Update() {
RaycastHit hit;
Ray ray;
if (Physics.Raycast (transform.position, Vector3.forward, Mathf.Infinity, layerMask)) {
Debug.Log ("The ray hit the floor");
if (debugWithMouse) {
Vector2 mousePos = new Vector2 (Input.mousePosition.x/Screen.width, Input.mousePosition.y/Screen.height);
ray = Camera.main.ViewportPointToRay (mousePos);
} else {
ray = new Ray (transform.position, transform.forward);
}
if (Physics.Raycast (ray, out hit)) {
Debug.DrawLine (transform.position, hit.point, Color.red);
}
if (Input.GetMouseButton (0)) {
if (Physics.Raycast (ray, out hit)) {
if (useViewHeight) {
targetIndicator.transform.position = new Vector3 (hit.point.x, hit.point.y + viewHeight, hit.point.z);
} else {
targetIndicator.transform.position = new Vector3 (hit.point.x, hit.point.y, hit.point.z);
}
targetIndicator.transform.LookAt (hit.point);
targetIndicator.GetComponent<Light>().intensity = 8;
genLine.genLine (new Vector3 (ray.origin.x + 2, ray.origin.y - .5f, ray.origin.z), hit.point);
line.material.SetTextureOffset ("_MainTex", new Vector2 (Time.timeSinceLevelLoad * -4f, 0f));
line.material.SetTextureScale ("_MainTex", new Vector2 (hit.point.magnitude, 1f));
}
}
if (Input.GetMouseButtonUp (0)) {
if (Physics.Raycast (ray, out hit)) {
if (!debugNoJump) {
if (useViewHeight) { //better way?
parent.transform.position = new Vector3 (hit.point.x, hit.point.y + viewHeight, hit.point.z);
} else {
parent.transform.position = new Vector3 (hit.point.x, hit.point.y, hit.point.z);
}
}
if (!debugLine) {
line.SetVertexCount (0);
}
}
targetIndicator.GetComponent<Light>().intensity = 0;
}
Debug.DrawRay (this.transform.position, ray.direction * 5, Color.blue);// .DrawLine(transform.position, hit.point, Color.red);
}
}
}
그게 효과가 있습니다. 나는 다른 약간의 비트를 바꿨고, 그것을 정리하고 공유하기 위해 게시 할 것이다. – P1505C
완벽한! 좋은 소리 –