using System.Collections; using System.Collections.Generic; using UnityEngine; [RequireComponent(typeof(Animator))] public class ArmMovement : MonoBehaviour { protected Animator animator; public bool ikActive = false; public Transform rightHandObj = null; public Transform lookObj = null; bool canpickup; void Start() { canpickup = false; animator = GetComponent(); } //a callback for calculating IK void OnAnimatorIK() { if (animator) { //if the IK is active, set the position and rotation directly to the goal. if (ikActive) { print(lookObj); // Set the look target position, if one has been assigned if (lookObj != null) { animator.SetLookAtWeight(1); animator.SetLookAtPosition(lookObj.position); } // Set the right hand target position and rotation, if one has been assigned if (canpickup == true) { if (rightHandObj != null) { print("pick up my hand"); animator.SetIKPositionWeight(AvatarIKGoal.RightHand, 1); animator.SetIKRotationWeight(AvatarIKGoal.RightHand, 1); animator.SetIKPosition(AvatarIKGoal.RightHand, rightHandObj.position); animator.SetIKRotation(AvatarIKGoal.RightHand, rightHandObj.rotation); } } } //if the IK is not active, set the position and rotation of the hand and head back to the original position else { animator.SetIKPositionWeight(AvatarIKGoal.RightHand, 0); animator.SetIKRotationWeight(AvatarIKGoal.RightHand, 0); animator.SetLookAtWeight(0); } } } private void OnTriggerEnter(Collider other) // to see when the player enters the collider { print("Collided with " + other.gameObject.tag); if (other.gameObject.tag == "Book") //on the object you want to pick up set the tag to be anything, in this case "book" { canpickup = true; //set the pick up bool to true } } }