// Update is called once per frame void Update() { if (ViveInput.GetButtonDown(Hand, ViveButton.Grip)) { var count = Physics.OverlapSphereNonAlloc(transform.position, 0.04f, cols); for (int i = 0; i < count; i++) { var body = cols[i].GetComponent <Rigidbody>(); if (body != null) { attachedBodies.Add(body); body.isKinematic = true; body.transform.SetParent(transform); } } } if (ViveInput.GetButtonUp(Hand, ViveButton.Grip)) { for (int i = 0; i < attachedBodies.Count; i++) { var body = attachedBodies[i]; body.transform.SetParent(null); body.isKinematic = false; body.velocity = ViveInput.GetVelocity(Hand); body.angularVelocity = ViveInput.GetAngularVelocity(Hand); attachedBodies.RemoveAt(i); } } }
// Update is called once per frame void Update() { if (grabedbody == null) { if (ViveInput.GetButtonDown(hand, ViveButton.Trigger)) { RaycastHit hit; Collider[] colider = Physics.OverlapSphere(ViveInput.GetPosition(hand), 0.09f); if (colider.Length > 0) { grabedbody = colider[0].GetComponent <Rigidbody>(); grabedbody.useGravity = false; grabedbody.isKinematic = true; } if (Physics.Raycast(ViveInput.GetPosition(hand), ViveInput.GetTransform(hand).forward, out hit)) { Debug.Log("here at raycast"); if (hit.rigidbody.gameObject.tag == "bowling_ball") { //var bullet= Instantiate(prefabinstition); // bullet.transform.position = hit.rigidbody.transform.position; Debug.Log("here with ball"); grabedbody = hit.rigidbody; grabedbody.useGravity = false; grabedbody.isKinematic = true; } // Destroy(prefabinstition); } } } else { grabedbody.transform.position = ViveInput.GetPosition(hand); grabedbody.transform.rotation = ViveInput.GetRotation(hand); if (ViveInput.GetButtonUp(hand, ViveButton.Trigger)) { grabedbody.angularVelocity = ViveInput.GetAngularVelocity(hand); grabedbody.velocity = ViveInput.GetVelocity(hand); grabedbody.isKinematic = false; grabedbody.useGravity = true; grabedbody = null; } } }
// Update is called once per frame void Update() { if (ViveInput.GetButtonDown(hand, ViveButton.Trigger)) { var numberOfColliders = Physics.OverlapSphereNonAlloc(transform.position, 0.05f, cols, grabLayer); if (numberOfColliders == 0) { return; } var rb = cols[0].GetComponent <Rigidbody>(); if (!rb) { return; } cols[0].gameObject.layer = 0; grabbedBody = rb; grabbedBody.transform.SetParent(transform); grabbedBody.isKinematic = true; grabbedBody.useGravity = false; } else if (ViveInput.GetButtonUp(hand, ViveButton.Trigger)) { if (!grabbedBody) { return; } cols[0].gameObject.layer = LayerMask.NameToLayer("lift"); grabbedBody.transform.SetParent(null); grabbedBody.isKinematic = false; grabbedBody.useGravity = true; grabbedBody.velocity = ViveInput.GetVelocity(hand); grabbedBody.angularVelocity = ViveInput.GetAngularVelocity(hand); grabbedBody = null; } }
// Update is called once per frame void Update() { RaycastHit hit; if (ViveInput.GetButtonState(ViveHand.Left, ViveButton.Trigger)) { line.enabled = true; if (Physics.Raycast(transform.position, transform.forward, out hit)) { line.SetPosition(1, new Vector3(0f, 0f, hit.distance)); } else { line.SetPosition(1, new Vector3(0f, 0f, 100f)); } } if (ViveInput.GetButtonUp(ViveHand.Left, ViveButton.Trigger)) { line.enabled = false; if (Physics.Raycast(transform.position, transform.forward, out hit)) { var btn = hit.collider.gameObject.GetComponent <Button>(); if (btn) { btn.onClick.Invoke(); } var MeshRendererfound = hit.collider.gameObject.GetComponent <MeshRenderer> (); if (MeshRendererfound) { MeshRendererfound.material = Material_Singletone.Instance.SelectMaterial; } } } }
// Update is called once per frame void Update() { if (ViveInput.GetButtonUp(ViveHand.Right, ViveButton.Trigger)) { } }