- Home /
UI representation of Gameobject at runtime
Hi,
I am working on a tower defense game. The tower can be configured with different parts which I achieve by having prefabs for each replaceable module. e.g. the user has several choices in terms of tower, turret type, buffs etc. The final towers are all different as per choices made by the player. The prefabs is a combination of several images, as there are moving parts.
I also want to have a static representation of the tower (as it appears after configurations) in the UI where all the actions (like repair, buff activate) will be. So there is a need to recreate the tower using Image components. What would be the best way to do this?
Below is what I can think of but have some problems for each.
[Working on this now] Create UI prefabs for each tower component - These corresponding prefabs will have to be assembled once the user has finished configuring the tower. This can be tedious as there are many parts for which a prefab will have to be created and every time there is an update to the images (position, rotation, etc.), the UI prefab will have to be updated.
[Tried this but not happy] Use a script to get all SpriteRenderer component in the gameobject and children, and create a new UI gameobject with Image components for each of them. This was doable, but sorting by the sorting order has to be done. Also the Canvas has to be world space otherwise the size and relative positioning of the images are not same. I am worried that this method can cause problems later with other UI.
Render Texture - Seems overkill as I do not want and updating image. Also needs another camera, etc.
Any Help is appreciated. Thank you.
Your answer
Follow this Question
Related Questions
Make touch buttons transparent 2 Answers
How to drag an instantiated UI element? 0 Answers
Anchoring a UI image to the top of another UI image. 1 Answer