Last active
February 7, 2022 23:01
-
-
Save tubakihimeLoveHate/408c2f06ff3c5d44615fe07be5a4e8e8 to your computer and use it in GitHub Desktop.
clickした先で衝突判定があった場合cloneを生成
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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