Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Hi there

I need some help with something that is bother me for 2 days already.

So i am deactivate a game object if the player collide with other game object, in order that what is in that script not to be called anymore and not working, i tried also only to disable the script but , the functions that are in that script still running after the script is disabled.

If anyone have a solution to this i will really really really really appreciate.


Thank you i own you a beer ;P

Answers

  • HNJHNJ Member

    What is the problem(s) you are exactly having?

  • in short , i will say even if the script is disable, the code is still running 😔

  • HNJHNJ Member

    When you disable a script or even the gameObject of that script, the script will not execute on its own (means Start and Update, OnTrigger etc. will not called)

    But if you execute a particular function from another script , it will be executed

    For example, lets say you have two scripts Foo and Bar as follows

    public class Foo : MonoBehaviour {
        void Start() {
            Debug.Log("Foo is active");
        }
    
        public void Func() {
            Debug.Log("Func executed");
        }
    }
    

    and

    public class Bar : MonoBehaviour {
        void Start() {
            Debug.Log("Bar is active");
            Foo.Func();
        }
    
        public void Func2() {
            Debug.Log("Func2 executed");
        }
    }
    


    Now suppose, Foo is disabled in inspector and Bar is active

    if you will run the game, The console will have

    Bar is active

    Func executed


    Because Foo is disabled, Foo's Start is not called, But Bar is enabled so Bar's Start is called and in Start, we are calling Foo.Func(), so Foo's Func is called

    But no one is calling Bar's Func2

    Even if we write

    Bar.Func2();

    in Foo's Start, it will not be called.

    Hope you understand

Sign In or Register to comment.