Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Unityのエディタ上で視線IKが動かせるスクリプトだよ
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
You can’t perform that action at this time.