Skip to content

Instantly share code, notes, and snippets.

@daichi-takezawa
Last active April 28, 2020 10:45
Show Gist options
  • Save daichi-takezawa/e4300a0c56b7142057603959518fd568 to your computer and use it in GitHub Desktop.
Save daichi-takezawa/e4300a0c56b7142057603959518fd568 to your computer and use it in GitHub Desktop.
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