Skip to content

Instantly share code, notes, and snippets.

@bdecarne
Created November 4, 2015 18:44
Show Gist options
  • Save bdecarne/9152cea14834d751cdbd to your computer and use it in GitHub Desktop.
Save bdecarne/9152cea14834d751cdbd to your computer and use it in GitHub Desktop.
Unity : ClickToInstantiate
using UnityEngine;
using System.Collections;
public class ClickToInstantiate : MonoBehaviour
{
public GameObject obj;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetButtonDown("Fire2"))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (GetComponent<Collider>().Raycast(ray, out hit, Mathf.Infinity))
{
Instantiate(obj, hit.point, Quaternion.identity);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment