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 /
avatar image
0
Question by holden15 · Jan 02, 2016 at 09:13 AM · unity 5unity5prefab changing at runtime

Trying to visually show the growth stages of a seed

I have an empty parent prefab, with 2 children under it. The parent prefab represents the seed, with no visual components. I currently have the first child active in the prefab, and the second child is inactive.

I simply would like the first child to be shown when the item is placed in my world (this is working currently), and then after a set amount of time I'd like the first child to go inactive, and the second child to display. I have all of the logic hooked up for knowing when to swap out the active prefab, I just don't know how to do it.

To throw a wrench into it, I plan on having more than one type of seed (orange, cactus, etc), and not all seeds will have the same amount of stages to their growth process. I'm trying to figure out a solution that will account for not just two stages, but 1, 2, or 3, etc.

Here is the logic I've written up so far - it is ready for the appearance swapping.

     private void FixedUpdate()
     {
         if (Time.time > mNextGrowthStage && !CanLoot)
         {
             mCurrentGrowthStage += 1;
             mNextGrowthStage = Time.time + GrowthStageDuration;
 
             // TODO: Insert visual appearance swap here.
 
             Debug.LogFormat("{0} has grown from stage {1} to stage {2}. There are {3} stages remaining. Next growth stage occurring in {4} seconds.",
                 this.Name, mCurrentGrowthStage - 1, mCurrentGrowthStage, NumberOfGrowthStages - mCurrentGrowthStage, GrowthStageDuration);
 
             if (mCurrentGrowthStage >= NumberOfGrowthStages)
             {
                 Debug.LogFormat("{0} has fully grown!", this.Name);
                 CanLoot = true;
             }
         }
     }

Any help is much appreciated. Thanks!

Comment
Add comment · Show 2
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 ShadyProductions · Jan 02, 2016 at 12:25 PM 0
Share
 public GameObject yourPlant; //declare your plant in inspector
 //or when the script is in the plant you can reference it in the start function as
 //yourPlant = gameObject;
 
 foreach (Transform child in yourPlant) //goes through every child of the gameObject
 {
   //child is your child transform
 //use if logic to check if it is the 2nd
 if (child.name == "secondStage") {
 child.gameObject.SetActive(true);
 } else { //anything else will be disabled?
 child.gameObject.SetActive(false);
 }
 }

Something like this?

avatar image ShadyProductions ShadyProductions · Jan 02, 2016 at 12:31 PM 0
Share

you could refine it into a function so you can call it easier in the future?

 void updateStageAppearance(string nameOfChild, GameObject plant) {
 //pass the nameOfChild into the if statement
 }

etc.. then you can easily call it updateStageAppearance("secondStage", yourPlant); like so.

0 Replies

· Add your reply
  • Sort: 

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

UNET Matchmaking Filter Issues 1 Answer

Unity 2d Top-Down Mouse Aiming Stutters When Moving 2 Answers

C# separation code help 1 Answer

Can I use GetComponents reference outside Of awake and start functions 1 Answer

Raycast do not detect when distance is closer or further than the max distance 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