private void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "pickup" && !picked && !inHand && !throwing) { picked p = other.gameObject.GetComponent <picked>(); p.approached = true; thisBall = other.gameObject; } }
private void OnTriggerExit(Collider other) { if (other.gameObject.tag == "pickup" && !inHand) { picked p = other.gameObject.GetComponent <picked>(); p.approached = false; thisBall = null; } }
// Update is called once per frame void Update() { dia.transform.forward = cam.transform.forward; if (!picked && thisBall != null && !inHand) { if (Input.GetKeyDown(KeyCode.E)) { picked = true; thisBall.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width * 5 / 6, Screen.height / 5, Camera.main.nearClipPlane + 1)); thisBall.transform.parent = cam.transform; thisBall.transform.forward = cam.transform.forward; Rigidbody rb = thisBall.GetComponent <Rigidbody>(); rb.isKinematic = true; picked ballP = thisBall.GetComponent <picked>(); ballP.approached = false; inHand = true; handBall = thisBall; throwing = true; dia.SetActive(true); } } if (picked && inHand && handBall != null) { if (Input.GetMouseButtonDown(0)) { picked = false; Rigidbody rb = thisBall.GetComponent <Rigidbody>(); rb.isKinematic = false; handBall.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width / 2, Screen.height / 2, Camera.main.nearClipPlane + 1)); handBall.transform.parent = null; picked ballP = handBall.GetComponent <picked>(); ballP.thrown = true; handBall = null; inHand = false; throwing = true; dia.SetActive(false); } if (Input.GetKeyDown(KeyCode.E) && !throwing) { picked = false; Rigidbody rb = thisBall.GetComponent <Rigidbody>(); rb.isKinematic = false; handBall.transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z) + transform.forward; handBall.transform.parent = null; handBall = null; inHand = false; throwing = true; dia.SetActive(false); } } }