- Home /
Switch Weapon using Animation
Sorry for the question, i know many question lkie this in forum. But all there is not useful for me. Basically i want to switch weapon using animation Take In. After the weapon is take in, a different weapon is play animation Take Out. How can i do that?
Answer by webcam · Jun 19, 2017 at 03:34 PM
You're going to want each of your weapons to have a script acting as a weapon controller with a reference to the weapons animator. Each weapon controller can have public functions for setting the proper parameters in your animator. This is a simple version of what you would need in your player controller.
public List<WeaponController> weapons;
public WeaponController equippedWeapon;
public void changeWeapon(int newWeaponIndex)
{
equippedWeapon.playTakeOutAnim();
equippedWeapon = weapons[newWeaponIndex];
equippedWeapon.playTakeInAnim();
}
But how can i play the animation Take In done before play the animation Take Out? i was tried using normalizedTime in AnimatorStateInfo, and properties length. I have heard about coroutine, but i'm not sure how to use this. Oh, sorry for my bad English :)).
Please don't post responses to answers as answers. There's an "Add comment" button under every answer. Please use this ins$$anonymous$$d in the future. I've moved your response to the answer you were responding to.
Your answer
![](https://koobas.hobune.stream/wayback/20220612124458im_/https://answers.unity.com/themes/thub/images/avi.jpg)