Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Jerakin · May 01, 2014 at 03:33 PM · prefabupdatechangechildren

Display one of prefab child

First of I am very new to Unity.

I have a script that places either prefab1 or prefab2 depending what keyboard button have been clicked.

Super simple:

 prefab1       prefab2   
 --child1      --child1
 --child2      --child2
 --child3      --child3


First of when I place the prefab it (of course) shows all models, that's not what I want. I want to place/show only the first child.

Then I want to "age" the prefab. After some time it should change to prefab1.child2 then after some more time it should change to prefab1.child3 and so on.

I don't want to hardcode children and such, that is where I encounter problems.

My question is:

Can I place a prefabs child then change that later? something like this pseudocode:

 if buttonClicked = "1"
     activePrefab = prefab1     
  
 if buttonClicked = "2"
     activePrefab = prefab2

 buttonClicked = "space"
    child = activePrefab.transform.GetChild(0).gameObject
    Instantiate (child , player.position, player.rotation)

 age = age + (Time.time)

 if age > 5
     newChild = activePrefab.transform.GetChild(1).gameObject
     Instantiate (newChild, child.position, child.rotation)


Does anyone have any ideas, know of an old thread, or seen a video somewhere about it?

Regards, Jerakin

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

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by ZenithCode · May 01, 2014 at 03:52 PM

I would suggest you write an 'aging' script and put it on the parent object.

On Awake() it hides all models, then as time goes by, the model is swapped according to your needs.

Comment
Add comment · Show 2 · 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 Jerakin · May 01, 2014 at 04:02 PM 0
Share

That sounds like a great idea, I have tried that approach already but couldn't really get them to be hidden. I tried to do it with GameObject.Find("child1").renderer.enabled = false; But even though I saw that it did set it to false in the inspector it didn't hide it. Do you got an idea why that was the case?

avatar image Jerakin · May 01, 2014 at 04:44 PM 1
Share

I got it to work with gameObject.transform.GetChild(0).gameObject.SetActive(false);

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

Changing prefab doesn't update instances (in scene aswell as in other prefabs).. 3 Answers

Prefab not changing variable's values 2 Answers

Why is instantiated animator prefabs are not working properly? 2 Answers

What process should I best use to properly create an updated copy of a Prefab? 1 Answer

Replacing a prefab with a new one to update model changes 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