• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
This question was closed Nov 11, 2015 at 03:04 PM by CrispyArrow for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by CrispyArrow · Oct 07, 2015 at 02:13 PM · parent-childenableddisabled

How to disable parent through its own child object.

I have a leveling representation on my game which uses a float of the player and compares it to another float. (basically, current experience compared to max experience of the current level). Once you reach the max float, an interger (the level) will increase with one.

Once you do this, a gameobject with 3 child objects will be enabled. these 3 child objects are 3 clickable sprites that serve as buttons.

(as the player, when you level up, ou get to choose between 3 upgrades, displayed as buttons)

What I want to do is allow any of the 3 buttons to disable it's parent, essentially disabling eachother so that you cannot reuse any of the buttons. in other words, once you press any of the 3 buttons, you cannot choose any other until you level up again.

Here's the onMouseUp functions of one of the buttons:

 void OnMouseUp(){
     hpIncrease.maxPlayerLives += 10;
     hpIncrease.playerLives += 10;
     level2.SetActiveRecursively(false);
 }

level2 is a public gameobject which finds the tag of the parent object like this:

 level2 = GameObject.FindGameObjectWithTag ("Level2");


This, however doesnt seem to work. It works only if the gameobject is already enabled when the game starts, but that's not what I want.

So in short: How do disable a gameobject through one of it's children, which in turn disables the children as well?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
8
Best Answer

Answer by dkjunior · Oct 07, 2015 at 07:28 PM

You can do this by accessing parent's transform. The following code will do the job assuming it's in the script attached to one of your child objects:

 void OnMouseUp() {
         this.transform.parent.gameObject.SetActive(false);
     }

Also, you don't need to disable all objects recursively, disabling only the parent object will do the job.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image shrutisingh25 · Jun 15, 2018 at 09:41 AM 0
Share

can't we disable the update function from the parent object.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

34 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

On Renderer Was Enabled? (C#) 0 Answers

Child always on parent top to get the number of dice 0 Answers

Help me with this parent-child relation. 2 Answers

How to disable child adopting the transform of its new parent object? 1 Answer

How do I differentiate between the triggers? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges