Files
VR-WuKong/Assets/GameRes/Main/SceneArt/VRScene/Scripts/HitBMain.cs
2025-11-14 18:44:06 +08:00

41 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HitBMain : MonoBehaviour
{
RaycastHit hit;
public Material mat;
GameObject hitTag;
// Start is called before the first frame update
void Start()
{
hitTag = GameObject.CreatePrimitive(PrimitiveType.Quad);
hitTag.transform.localScale = Vector3.one * 0.5f;
hitTag.GetComponent<MeshRenderer>().material = mat;
Destroy(hitTag.GetComponent<MeshCollider>());
}
// Update is called once per frame
void Update()
{
if (Physics.Raycast(new Ray(Camera.main.transform.position, Camera.main.transform.forward), out hit, 1, 1 << LayerMask.NameToLayer("Wall")))
{
hitTag.SetActive(true);
hitTag.transform.position = hit.point;
hitTag.transform.rotation = Quaternion.LookRotation(Camera.main.transform.forward);
}
else
{
hitTag.SetActive(false);
}
}
private void OnDrawGizmos()
{
//Gizmos.color = Color.green;
//Gizmos.DrawRay(Camera.main.transform.position, Camera.main.transform.forward * 1);
}
}