I'm trying to make a game where you're a boy and you can transform into a deer. I don't know how to make the player transform into a deer when pressing a button. Can someone please tell me how to make the player transform into a deer when pressing a button and how to make the deer transform back into the player when pressing the button again?
CodePudding user response:
There are 2 ways depending on what you want exactly.
1.Transformation without an animation, you can do this by having 2 separate models
public GameObject boy;
public GameObject deer;
//Give both objects the same tag and don't add anything else under the
tag in order for this to work
private Transform currentPosition;
private void Start()
{
deer.SetActive(false);
}
public void TransformButton()
{
currentPosition = GameObject.FindObjectWithTag(LayerMask.NameToLayer("TransformationTag"));
//Unity doesn't pick up disabled GameObjects so it will pick up only the
//active state (the active object)
boy.SetActive(!activeInHierarchy);
deer.SetActive(!activeInHierarchy);
GameObject.FindObjectWithTag(LayerMask.NameToLayer("TransformationTag")).getComponent<Transform>() = currentPosition;
}
I recommend this way if your deer and boy have different scripts you could also play an animation on click (apply this animation to the active character) and when it is done (below is how to check if it is done) you can trigger the code above https://answers.unity.com/questions/362629/how-can-i-check-if-an-animation-is-being-played-or.html I am pretty sure there are other better ways but this is the way I do it
The other way which is probably easier if you are good at animating is to just trigger an animation using the animation bools when the button is clicked but I haven't tried this way because I'm not that good at animation. Instead I use the first way (usually for switching skins in a shop for example) but I never did animations that completely change the size ratio so much so I don't know how well would it work (I usually do 1:1 transformations like humanoid to humanoid or tank to tank so you will have to experiment a bit)
CodePudding user response:
I dont think that this is possible in unity. Maybe there are some Assets that offer something like this.
But you could create a similar effect with Blender. Check out Morphing Shape Animations. There are some cool tutorials out there Morphing Shape Animations in Blender