Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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.

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

Does activating a parent activates children (MB's Awake()) 1 Answer

Selectively enable and disable Gamepads?,D 0 Answers

How to make Child hanging above rotating parent 0 Answers

SOLVED. How can I use one parent object animator to control multiple child sprite animations? 1 Answer

How can the pivot point of a object be changed during Runtime? 0 Answers


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