I’m doing the Space Shooter Unity tutorial, and in the “Extending the tutorial” video they make different Prefab for each kind of asteroid. Basically each asteroid has a logical GameObject, and other GameObject as its child for art work. But for all 3 kinds of asteroid, the logic is the same, just the art that is different.
My question is: is there a way to have the same logical parent GameObject hold the three models, and then choose which of them will spawn?
What I want to do is: “This object has the logic that will be inhereted by its children, but only one children will spawn at a time.”
Thanks.
Really, that sounds like you’re trying to make it a bit more complicated than needed. But if it’s just a matter of changing out a sprite, you can spawn the gameobject and then have some logic to pick a random sprite.
If it’s different models, then again, you can just pick a random model and attach it as a child. You can spawn a parent and then spawn a child and attach it.
Now, I haven’t looked at the tutorial, so I don’t know what logic they are using to detect when a bullet hits an asteroid, but if they are using certain colliders, you’ll just need to make sure the collider works for all sprites use. I also don’t know what scripts they are using and if anything would have to be hooked up.
Otherwise, there isn’t a reason not to use three prefabs.
In the case of the tutorial, the colliders would need ajustment, yes. I’m asking because I was wondering “if all asteroids follow the same rules, why shouldn’t I do all of them with the same parent class that dictates those rules? And how can I do that?”.
But thanks. I think instantiating the logic object → randomize one out of three art objects and make an instance of it → attach the art object as child of the logic object, works for what I was wondering.