Enable/disable is not working as expected

Hi everyone,

To handle pausing i created a base class called Stoppables and add a listener to it which listens the pause event. When game is paused i set this.enabled = false; in Stoppable script to ensure that each script derived form Stoppables stop calling update. I’m not sure if this is the best approach but i choose this over creating an interface for stoppable objects.

The problem is this works for two out of three scripts which of all are attached to the same gameobject and at the same level of hierarchy. I’m sure that all these three scripts are derived from Stoppables. Am i missing something?

Any suggestions will be appreciated. Thanks in advence…

You can say when time is = 0 player.SetActive(false); when 1 it’s set to true

When game is paused i set
this.enabled = false; in Stoppable
script to ensure that each script
derived form Stoppables stop calling
update.

You can’t use inheritance to do something like this.
I mean even if it did work like that, the property “enabled” is already inherited from the Behaviour class, so changing its value would apply to all (Mono)Behaviours and stop all your scripts.

You should just use a static variable or such. Or use GetObjectsOfType< Stoppables >() and set enabled to all of them.

Inheritance is just a way to organise your code and to make a system where you don’t have to copy/rewrite the common code when making classes that have a lot in common. Or to enable putting different classes into the same typed collection. Each instance of each subclass is still its own… instance, and all its variables are its own. The this keyword also always refers to just 1 instance.