I am attempting to create a prefab GameObject based on the location of a mouse click. As far as I can tell, the code is correct… but nothing happens. Any suggestions on where I have gone wrong?
The script is a component of the MainCamera, with the prefab object (just a sphere right now) connected to the attribute “bubble.”
using UnityEngine;
using System.Collections;
public class BubbleTap : MonoBehaviour {
Ray ray;
RaycastHit hit;
public GameObject bubble;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Input.GetButtonDown("Fire1"))
{
if(Physics.Raycast(ray,out hit))
{
GameObject obj = Instantiate(bubble, new Vector3(hit.point.x,hit.point.y,hit.point.z), Quaternion.identity) as GameObject;
}
}
}
}