Skip to content

Instantly share code, notes, and snippets.

@tubakihimeLoveHate
Last active February 7, 2022 23:01
Show Gist options
  • Save tubakihimeLoveHate/408c2f06ff3c5d44615fe07be5a4e8e8 to your computer and use it in GitHub Desktop.
Save tubakihimeLoveHate/408c2f06ff3c5d44615fe07be5a4e8e8 to your computer and use it in GitHub Desktop.
clickした先で衝突判定があった場合cloneを生成
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CreateRayPoint : MonoBehaviour
{
[SerializeField]
private float distance = 20.0f;
[SerializeField]
private GameObject clone;
private Camera camera;
private void Start()
{
camera = GetComponent<Camera>();
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonUp(0))
{
Ray ray = camera.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, distance))
{
Instantiate(clone, hit.point, Quaternion.identity);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment