111
This commit is contained in:
40
Assets/GameRes/Main/SceneArt/VRScene/Scripts/HitBMain.cs
Normal file
40
Assets/GameRes/Main/SceneArt/VRScene/Scripts/HitBMain.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user