Search code examples
c#visual-studiounity-game-enginegame-development2d-games

So how do i disable a script in untiy and enable it in the same public void(idk the name for it)


I know how to disable it but I don't know how to enable it in the same void.

I have tried making another public void called playerRevive and in that put playerMovement.enabled = true; and tried to enable it in the update method and it said this NullReferenceException: Object reference not set to an instance of an object

what do I do

BTW it is a 2D game just for your information


Solution

  • As @Iggy said, you can't call MonoBehaviour methods from disabled objects. But you can reference this disabled object to another script and call method(s) from active object in the hierarchy.