gpt4 book ai didi

c# - 光线转换到 Unity 中的特定层

转载 作者:行者123 更新时间:2023-12-02 00:40:50 25 4
gpt4 key购买 nike

<分区>

我正在使用 GVRTeleport 脚本来允许使用纸板应用进行传送。我希望传送的光线转换忽略除一层以外的所有层。通过 this页面 我相应地修改了脚本(抱歉,无法找到此代码所有者的原始链接),但现在传送脚本什么也看不到。有任何想法吗?我的地板层是第 8 层,这是我希望此光线转换与之交互的层。

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);
}
}
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com