Definition
HidePrefabInstance(string prefabInstanceName)
Description
This function hides the prefab instance prefabInstanceName. To view the name of prefab instances, open the VScene and click on the desired Prefab Instance in the “Prefabs and GUIs” section and press the Edit button. You can also access the names of prefab instances from the Script Utility section of the script editor ( Tools > Script Editor > Tools > Script Utility). In the dialog that appears, you can view and copy the name of the prefab instance.
Parameters
prefabInstanceName
Specifies the name of the prefab instance. You can also use the name “this” for this parameter. In this case, “this” refers to the prefab instance that this script is attached to.
Example 1
timer = 0.0 hidden = false function Init() end function Update() timer = timer + GetElapsedTime() if timer >= 5.0 and not hidden then HidePrefabInstance("1_VandaEngine17-SamplePack1_eggbox") hidden = true end end
After 5.0 seconds, HidePrefabInstance function will hide “1_VandaEngine17-SamplePack1_eggbox” prefab instance.
Example 2
--name of the script is HidePrefabInstance2.lua timer = 0.0 hidden = false function Init() end function Update() timer = timer + GetElapsedTime() if timer >= 5.0 and not hidden then HidePrefabInstance("this") hidden = true end end
If, in the Prefab Editor, you attach HidePrefabInstance2.lua script to a Prefab, then “this” parameter in the HidePrefabInstance function will point to instances of that Prefab in current VScene. For example, if you have an Instance named instance1_a from a Prefab named a to which this script is attached, “this” in HidePrefabInstance function refers to the name instance1_a.
This script hides current prefab instance after 5.0 seconds.
HidePrefabInstance