I’m trying to get an object to instantiate upon click. When I try to test out my script i get
NullReferenceException: Object reference not set to an instance of an object
blockSpawn.Update () (at Assets/scripts/blockSpawn.js:10)
as an error.
I’ve been trying to fix this for around 5 hours now with no luck… I’m new to this so I may be missing something simple. I appreciate any help with this issue.
var block : GameObject;
function Start(){
}
function Update () {
var mousex = Input.mousePosition.x;
var mousey = Input.mousePosition.y;
var ray = Camera.main.ScreenPointToRay (Vector3(mousex,mousey,0));
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 200)) {
}
if ( Input.GetMouseButtonDown(0) )
{
var createBlock = Instantiate(block, hit.point, Quaternion.identity);
}
else {}
}
Thanks again for the help guys!