- Home /
Character Transform
Hello I’m a newbie into the Unity3D world. I have a question and hope someone can help. Does anyone know about changing a character to another character in C#? I’m trying to make my game where you are the zombie player and you run up to human people (Ai Spawners) and when you touch them they turn into a zombie. The Ai’s change and become the same type of character as the player character. That’s the concept I’m trying to create and having an issue with.
Answer by darkStar27 · May 07, 2019 at 04:43 AM
I don't know if its the best way to solve this problem but the way that i would have approached this problem is -
You need a game object that contains all your custom components (Scripts) that you have on your character and make it as parent of your models. This way all you have to do is switch between the model on and off and all your functionality still remains on your player.
If however, once the human becomes the zombie and you need different functionality for you zombie guy , you can modularize your code accordingly and attach the unique functionalities to specific character gameObjects.
Hope it helps you..
Yea, my way is definitely not the most elegant, but for someone starting out I figured it'd be the simplest. In my head their human is a capsule with a skin tone, and the zombie is a green one.
Oh, sorry I wasn't talking about your approach. I just wasn't sure that my whether my way would be the best one to around this problem.
But yeah it is better to use SetActive then to Instantiate and Destroy gameObjects, also as you just want convert the same character to the zombie one, it is better to make them child of a GameObject, that way you wouldn't have to worry about the positioning of the zombie to be exact same as the human cause it always will be..
Answer by K-Anator · May 07, 2019 at 04:34 AM
One way you could go about it, would be the same way that simple destructible objects are done.
Have a script checking for a collision or trigger event involving a zombie/human, and when that event is detected, create an instance of the zombie game object, and destroy the human game object.
I'd suggest taking a look at https://youtu.be/EgNV0PWVaS8 to see how you can replace one object with another.
Answer by gusval85 · May 10, 2019 at 05:13 AM
@K-ANator @darkStar27 ,
Thank you so much guys. I’m going to try both ways. The concept I want to do is much harder than I thought. I’m sure I will do good with your advice. Thanks.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Translate from JS to C# localEulerAngles 1 Answer
Distribute terrain in zones 3 Answers
Can I transform my Character into a different object? 0 Answers
Push character away 0 Answers