void pickup() { // create new block in hand if (Input.GetKeyDown(KeyCode.LeftShift)) { spawnObject(objectToSpawn[SelectedCube]); } // avoid out-of-bounds /*if (SelectedCube > objectToSpawn.Length - 1) { * SelectedCube = 0; * } * if (SelectedCube < 0) { * SelectedCube = objectToSpawn.Length - 1; * }*/ // change selected block SelectedCube += Mathf.RoundToInt(Input.GetAxis("Mouse ScrollWheel")); Debug.Log(Mathf.RoundToInt(Input.GetAxis("Mouse ScrollWheel"))); //Txt_SelectedCube.text = SelectedCube.ToString(); // pickup existing block if (Input.GetKeyDown(KeyCode.E)) { 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)) { pickupable p = hit.collider.GetComponent <pickupable>(); if (p != null) { carrying = true; carriedObject = p.gameObject; p.gameObject.GetComponent <Rigidbody> ().isKinematic = true; yOffset = 0f; zOffset = 0f; } } } }
void pickup() { if (Input.GetKeyDown(KeyCode.E)) { 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)) { pickupable p = hit.collider.GetComponent <pickupable> (); if (p != null) { carrying = true; carriedObject = p.gameObject; p.GetComponent <Rigidbody>().useGravity = false; p.GetComponent <Rigidbody>().freezeRotation = true;//THIS LINE FIXES WEIRD PHYSICS ON PICKED UP OBJECTS!!!!!!!!!! } } } }