(スクリプト)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RayHitPointGene : MonoBehaviour
{
public GameObject blockPrefab;
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
if (hit.transform.gameObject.tag == "Floor")
{
print(hit.point);
Instantiate(blockPrefab, hit.point, Quaternion.identity);
}
}
}
}
}
(実行結果)