- Home /
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!
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?
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.
Your answer
Follow this Question
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