#Question about "Multi-Stage Objects"

1 messages · Page 1 of 1 (latest)

feral knot
#

Hey there! I'm currently in Uni for game programming and got a question about our unity semester-project:

I need to add a "Plant" Prefab. The plant should grow over time and be able to be "cut" by the player. I plan to do this using a simple Stage-System where the plant grows in 5 different stages, basically just like the Crops in Minecraft lol.

However, im unsure what the most efficient way would be to approach this in unity. My current thought would be to give the prefab 5 child-objects, each with its own sprite and collider. When the plant grows it would then turn off the previous child-object and turn on the one of the new stage.

Would this be a solid implementation?

tribal canopy
#

I would give the Plant component a list of stages

#
[System.Serializable]
public class Stage {
  public Sprite sprite;
  public float growthTime;
  public bool givesDrops;
}

Maybe like this.

#

Then you can add this to your Plant component:

[SerializeField] List<Stage> stages;
#

you'll be able to create a list of Stages in the inspector. Each Stage includes the sprite, the time taken to grow, and whether or not you get anything from breaking the crop.

#

You could also give it a list of drops instead

#

If you want to have more elaborate changes, you might just wind up giving the plant different objects to turn on and off.

#

in that case, I'd make a small tweak to the Stage class...

#
[System.Serializable]
public class Stage {
  public GameObject stageObject;
  public float growthTime;
  public bool givesDrops;
}
feral knot
#

Thank you for your response!
My biggest issue is that the plant needs to get a bigger collider as it grows, and since ive been told switching out colliders on a single object is a bad idea i think using multiple children would be the way to go.

Though i absolutely didn't consider the creation of a Stage-Class. That is actually a pretty good idea, thank you for that!

tribal canopy
#

I don't think switching one collider off and another one on is bad, but it is more fiddly