I am using the following code to destroy a script that is a component of a certain game object, but I am not destroying the game object itself:
if (gameObject.name == "Reality Monitor")
How do I “respawn” this script in the object after a certain period of time?
Thanks in advance.
You can destroy a component by using Destroy function.
And you can add a component by using AddComponent function.
Good day gabbil-
You can not “restore” a destroyed script. You can instantiate a new copy of the script (but all registred data will be reset). With
But, why you want to destroy it if you will need it after? You can just disable it like any other component, with
gameObject.GetComponent<WebcamPreview>().enable = false;
So it will not be active until do make enable true again.