Hallo,
I´m trying to instantiate a prefab at mouse position. My script compiles without error,
using UnityEngine;
using System.Collections;
public class InstantiatePrefabAtMouse : MonoBehaviour
{
public GameObject Boje;
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
Debug.Log("Mouse is down");
RaycastHit hitInfo = new RaycastHit();
bool hit = Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo);
if (hit)
{
GameObject BojeInstance;
BojeInstance = Instantiate(Boje, hitInfo.point, Quaternion.identity) as GameObject;
}
}
}
}
But when I click in my scene I get the following error:
![]()
What did I do wrong ?