Hello good people,

I’m new to booleans (and scripting for that matter) and i’ve run into a problem. I want a prefab to instantiate OnKeyDown, but after that I want that key to go dead, so it only instatiates the prefab once. The script below doesn’t actually instantiate anything.

I think it has something to do with line 19. How do I prevent another instantiation OnKeyDown after it has completed?

Thanks!

#pragma strict

var tilePrefab : GameObject;
var canCreate : boolean;

function Start ()
{
	canCreate = true;
}


function Update ()
{
	if(canCreate == true)
	{
		if(Input.GetKeyDown("c"))
		var instance : GameObject = Instantiate(tilePrefab);
		{
		canCreate = false;
		}
	}
}

Try this

 var tilePrefab : GameObject;
 private var canCreate : boolean = true;
 
 function Update (){
     if(canCreate){
         if(Input.GetKeyDown(KeyCode.C)){
             canCreate = false;
             var instance : GameObject = Instantiate(tilePrefab);
         }
     }
 }