Ok, I am going to give you this one, as it can be confusing how to only make something happen once in a game lifetime, and you have shown effort in thinking about the problem.
You have the right idea with a boolean, so lets start there :
var hasShownDoorPopup : boolean = false;
now GetComponent is quite heavy on the processor, so let’s first check if the door popup has been done :
// note the ! this is the same as saying if ( hasShownDoorPopup == false )
if ( !hasShownDoorPopup )
{
//
}
so now the DoorScript can be checked. Remember to use == in a conditional (you only have one equals in your example if statement). Also try not to use strings when using GetComponent, just typecast to the name of your script :
After that, instantiate your prefab , and then set hasShownDoorPopup to true. Now this part of the code will not be executed again in the current game lifetime.
Here is a full example :
var hasShownDoorPopup : boolean = false;
// in your function
if ( !hasShownDoorPopup )
{
if ( GetComponent( DoorScript ).isDoorOpen == true )
{
// instantiate prefab
// set boolean to true so this doesn't happen again
hasShownDoorPopup = true;
}
}
You almost answered yourself : Use the Instantiate function
Something like:
Instantiate(YourPrefab, new Vector3(X, Y, Z), [Quaternion.identity][1])
A little advice. If you’re using this line “if (GetComponent(“DoorScript”).isDoorOpen = true)” in an Update() function, you should consider storing it before (may be in the Start() function, because GetComponent is slow.