void pickup() { if (Input.GetButtonUp("Interaction")) //if they pushed the button, { if (mainCamera == null) //check for camera { mainCamera = GameObject.FindWithTag("MainCamera"); } int x = Screen.width / 2; int y = Screen.height / 2; Ray ray = mainCamera.GetComponent <Camera>().ScreenPointToRay(new Vector3(x, y)); RaycastHit hit; if (Physics.Raycast(ray, out hit)) //did the raycast hit anything { PickupAble p = hit.collider.GetComponent <PickupAble>(); if (p != null) { carrying = true; p.gameObject.GetComponent <Rigidbody>().useGravity = false; carriedObject = p.gameObject; Physics.IgnoreCollision(carriedObject.transform.GetComponent <Collider>(), GetComponent <Collider>()); if (pGun) { pGun.setCanShoot(false); } } } } }