具体实现方式
using UnityEngine;
using UnityEditor;
public class Example : MonoBehaviour
{
[SerializeField] private GameObject decal;
//[SerializeField] private GameObject effect;
//private bool flag;
//private RaycastHit hit;
private void Update()
{
//Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
//flag = Physics.Raycast(ray, out hit);
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 200))
{
if (Input.GetMouseButtonDown(0))
{
var decalInstance = Instantiate(decal);
//decalInstance.transform.position = hit.point + hit.normal * .02f;
decalInstance.transform.position = hit.point;
decalInstance.transform.forward = hit.normal;//forward z轴 up x轴 right y轴
}
}
}
}