using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Text; using UnityEngine; public class PickUp : MonoBehaviour { public GameObject myHands; //reference to your hands/the position where you want your object to go bool canpickup; //a bool to see if you can or cant pick up the item GameObject ObjectIwantToPickUp; // the gameobject onwhich you collided with bool enter; // Start is called before the first frame update void Start() { canpickup = false; //setting both to false enter = false; print("Enter"); } IEnumerator your_timer() { enter = false; //Debug.Log("Your enter Coroutine at" + Time.time); yield return new WaitForSeconds(1.0f); enter = true; } // Update is called once per frame void Update() { if (canpickup == true) // if you enter thecollider of the objecct { if (enter == false) { StartCoroutine(your_timer()); } if (enter == true) { ObjectIwantToPickUp.GetComponent().isKinematic = true; //makes the rigidbody not be acted upon by forces ObjectIwantToPickUp.transform.position = myHands.transform.position; // sets the position of the object to your hand position ObjectIwantToPickUp.transform.parent = myHands.transform; //makes the object become a child of the parent so that it moves with the hands } } } private void OnTriggerEnter(Collider other) // to see when the player enters the collider { 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 ObjectIwantToPickUp = other.gameObject; //set the gameobject you collided with to one you can reference print(canpickup); } } private void OnTriggerExit(Collider other) { canpickup = false; //when you leave the collider set the canpickup bool to false } }