Last active
April 28, 2020 10:45
-
-
Save daichi-takezawa/e4300a0c56b7142057603959518fd568 to your computer and use it in GitHub Desktop.
This file contains 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 DrawOb : MonoBehaviour | |
{ | |
private Camera camera; | |
public GameObject InstantiatedOb; | |
void Start() | |
{ | |
camera = Camera.main; | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
Click(); | |
} | |
private void Click() | |
{ | |
if (Input.GetMouseButton(0)) | |
{ | |
Ray ray = new Ray(); | |
RaycastHit hit = new RaycastHit(); | |
ray = camera.ScreenPointToRay(Input.mousePosition); | |
if (Physics.Raycast(ray.origin, ray.direction, out hit, 10) ) | |
{ | |
Debug.Log(ray.GetPoint(10)); | |
Vector3 pos = new Vector3(ray.GetPoint(10).x, ray.GetPoint(10).y, -5); | |
Instantiate(InstantiatedOb, pos, Quaternion.identity); | |
} | |
else | |
{ | |
Debug.Log(ray.GetPoint(10)); | |
Vector3 pos = new Vector3(ray.GetPoint(10).x, ray.GetPoint(10).y, -5); | |
Instantiate(InstantiatedOb, pos, Quaternion.identity); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment