Advertisement
romi_fauzi

AnimatorHelper

Oct 8th, 2020
2,064
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.73 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class AnimatorHelper : MonoBehaviour
  6. {
  7.     [SerializeField] float xzOffset = 1.1f, yOffset = 1f;
  8.     private Animator animator;
  9.  
  10.     // Start is called before the first frame update
  11.     void Start()
  12.     {
  13.         animator = GetComponent<Animator>();
  14.     }
  15.  
  16.     private void OnAnimatorMove()
  17.     {
  18.         if (animator)
  19.         {
  20.             Vector3 offset = transform.parent.position;
  21.             offset.x += animator.deltaPosition.x * xzOffset;
  22.             offset.z += animator.deltaPosition.z * xzOffset;
  23.             offset.y += animator.deltaPosition.y * yOffset;
  24.             transform.parent.position = offset;
  25.         }
  26.     }
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement