- Home /
How can I spawn a character when clicking a button, but then when I click a different button, delete the old one and spawn a new one?
I am making a character customization screen and I am at the point where I want to show a preview of what the character looks like before the player selects him. I want to know how I would go about doing this.
Example -
Player selected "Mage" as a character. Shows preview of a mage model along with description and stats.
Player selects "Warrior" next. Deletes the preview of mage model and shows a preview of the warrior model along with description and stats.
For right now I am using just basic 3D shapes (cubes, capsules, ect.) that come with unity. Lets say that the mage model is a cube and the warrior is a capsule. How would I spawn a cube when the button is clicked, but then delete it when the warrior is clicked and spawn the capsule?
You could load all the models, then just show (i.e. set as visible) the one that has been selected for preview. Constantly instantiating and destroying GameObjects is not great for performance.
I don't have much experience with Instantiating, actually none at all. This is my first real project that I'm working on. If you could help me a little further, that would nice. Thanks!
Answer by justin35f · Dec 15, 2014 at 01:00 AM
I would recommend that you instantiate all of your 'Characters' and then disable them all via script. Then keep track of the 'currently selected' character and whenever a button is pressed, disable the currently selected character, enable that new characters game object and then set it to the 'currently selected'.
If you need more explanation, please let me know!
Your answer
Follow this Question
Related Questions
Character Creation Screen 2 Answers
2D Platformer and Character Creation 0 Answers
Help with NullReferenceException 1 Answer