Caminhoneiro

OverrideAnim

Jul 6th, 2021
1,101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1.  
  2.     public AnimationClip[] weaponAnimationClip;
  3.  
  4.     protected Animator animator;
  5.     protected AnimatorOverrideController animatorOverrideController;
  6.  
  7.     protected int weaponIndex;
  8.  
  9.     public void Start()
  10.     {
  11.         animator = GetComponent<Animator>();
  12.         weaponIndex = 0;
  13.  
  14.         animatorOverrideController = new AnimatorOverrideController(animator.runtimeAnimatorController);
  15.         animator.runtimeAnimatorController = animatorOverrideController;
  16.     }
  17.  
  18.     public void Update()
  19.     {
  20.         if (Input.GetButtonDown("NextWeapon"))
  21.         {
  22.             weaponIndex = (weaponIndex + 1) % weaponAnimationClip.Length;
  23.             animatorOverrideController["shot"] = weaponAnimationClip[weaponIndex];
  24.         }
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment