1

I've got this part of script

void Update()
    {
        if (Pause_Menu.retryed)
        {
            Debug.Log(this.name);
            Destroy(this);
        }
    } 

It is attached to two object, but no matter which object exists, the first of them is still will be not destroyed and console will stay empty and the second one will be destroyed and console will has his name. What kind of problem it can be?

And also strange thing. If I'm trying destroy the first and the second externally by GameObject.Find() I will find also one of them, like second even doesn't exist, but it does.

4
  • Destroy(this); will destroy the component, so if you intended to destroy the game object you need Destroy(gameObject); Commented May 24, 2022 at 11:22
  • @Everts Thanks. But then I don't understand, this method still works for the first object, but not the second. And if I replace it on Debug.Log(this.gameObject.name); and Destroy(this.gameObject); it doesn't change something Commented May 24, 2022 at 11:30
  • The first GameObject is inactive, or this component is disabled, or Pause_Menu.retryed is false. Commented May 24, 2022 at 11:37
  • @shingo Thanks, I thought the same, but I've checked literally hundred times, both of them are active Commented May 24, 2022 at 11:40

1 Answer 1

1

Yah, the problem was in difference between gameObject and component, I used it wrong. Thanks everyone and especially @Everts!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.