Created
November 4, 2015 18:44
-
-
Save bdecarne/9152cea14834d751cdbd to your computer and use it in GitHub Desktop.
Unity : ClickToInstantiate
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 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