Hi,
I am trying to enable an object when it has been destroyed previously. What I am trying to do it turn off a script temporarily and then be turned on again after the player presses a key. Is there another script to disable and enable scripts. I searched through the API and the tutorials and couldn’t find anything. I have tried using “SetActive” but that only works for gameobjects. Thank you in advance.
You can enable or disable Behaviours be setting the “enabled” bool.
In your case, for example, running the code on the ABC script:
player.getComponent<xyz>().enabled=false; // disable the script running on the player
gameObject.getComponent<abc>.enabled=false; //disable the abc script
You might want to simply use gameObject.Destroy() if you’re not using the object for anything else, though.
Destroyed means it’s gone forever. No take backs. You can set enabled to false instead. Or you can use AddComponent to recreate the component.