// Update is called once per frame void Update() { if (!isLocalPlayer) { return; } playerHead.transform.SetPositionAndRotation(myCamera.transform.position, myCamera.transform.rotation); playerLeftContr.transform.SetPositionAndRotation(myLeftContr.transform.position, myLeftContr.transform.rotation); playerRightContr.transform.SetPositionAndRotation(myRightContr.transform.position, myRightContr.transform.rotation); if (controller.GetHairTrigger()) { if (Cube == null && Physics.Raycast(myRightContr.transform.position, myRightContr.transform.forward, out hit, 30, ~(1 << 8))) { if (hit.collider.tag == "Cube") { CmdClick(); Cube = hit.collider.GetComponent <CubeMovementScript>(); } } } else { if (Cube != null) { CmdUnClick(); Cube = null; } } Debug.DrawLine(playerRightContr.transform.position, playerRightContr.transform.forward * 30, Color.red); }
void CmdUnClick() { if (Cube == null) { return; } Cube.Throw(); Cube = null; }
void CmdClick() { if (Cube == null) { if (Physics.Raycast(playerRightContr.transform.position, playerRightContr.transform.forward, out hit, 30, ~(1 << 8))) { if (hit.collider.tag == "Cube") { Cube = hit.collider.GetComponent <CubeMovementScript>(); Cube.Parent = playerRightContr.transform.GetChild(0).gameObject; } } } }