Created
July 6, 2019 03:28
-
-
Save halby24/3e63b6bd7946852e21be86683acdea4e to your computer and use it in GitHub Desktop.
Unityのエディタ上で視線IKが動かせるスクリプトだよ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
[ExecuteInEditMode] | |
public class LookAtIKInEditMode : MonoBehaviour | |
{ | |
[SerializeField] private bool active; | |
[SerializeField] private Transform target; | |
[SerializeField, Range(0f, 1f)] private float lookAt; | |
[SerializeField, Range(0f, 1f)] private float body; | |
[SerializeField, Range(0f, 1f)] private float head; | |
[SerializeField, Range(0f, 1f)] private float eye; | |
[SerializeField, Range(0f, 1f)] private float clamp; | |
private Animator _animator; | |
// Start is called before the first frame update | |
void Start() | |
{ | |
_animator = GetComponent<Animator>(); | |
} | |
private void Update() | |
{ | |
_animator.Update(0); | |
} | |
private void OnAnimatorIK(int layerIndex) | |
{ | |
if (active) | |
{ | |
_animator.SetLookAtWeight(lookAt, body, head, eye, clamp); | |
_animator.SetLookAtPosition(target.position); | |
} | |
else | |
{ | |
_animator.SetLookAtWeight(0); | |
_animator.SetLookAtPosition(_animator.bodyPosition + _animator.bodyRotation * new Vector3(0, 0.5f, 1)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment