// Update is called once per frame void Update() { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //if we click when we have an object, drop it if (Input.GetMouseButtonDown(0) && ConnectedBody != null) { ConnectedBody.useGravity = true; spring.connectedBody = null; ConnectedBody = null; lineRender.ToggleLine(false); if (characterAgent != null) { StartCoroutine(restartCharacter(characterAgent)); characterAgent = null; } return; } //check for what we are clicking on if (Physics.Raycast(ray, out hit)) { if (hit.transform.tag == "Ground") { transform.position = new Vector3(hit.point.x, hit.point.y + 2.0f, hit.point.z); } else if (hit.transform.tag == "Object") { if (Input.GetMouseButtonDown(0) && ConnectedBody == null) { if (hit.transform.gameObject.GetComponent <NavMeshAgent>() != null) { characterAgent = hit.transform.gameObject.GetComponent <NavMeshAgent>(); grabCharacter(characterAgent); } ConnectedBody = hit.transform.gameObject.GetComponent <Rigidbody> (); ConnectedBody.useGravity = false; spring.connectedBody = ConnectedBody; spring.massScale = ConnectedBody.mass; lineRender.ToggleLine(true); } } } //continually draw the line if (ConnectedBody != null && lineRender != null) { lineRender.SetDrawValues(Player.position, this.transform.position, ConnectedBody.transform.position); lineRender.DrawCurve(); } }
// Update is called once per frame void Update() { //draw line GetComponent <LineRenderer>().SetPosition(0, transform.position); GetComponent <LineRenderer>().SetPosition(1, spring.transform.position); //move spring farther and cloaser to the player if (OVRInput.Get(OVRInput.Button.PrimaryTouchpad)) { Vector2 touchInput = OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad); spring.gameObject.transform.localPosition += (transform.worldToLocalMatrix.MultiplyVector(transform.forward) * (touchInput.y * .1f)); } if (OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger)) { RaycastHit hit; Ray ray = new Ray(transform.position, transform.forward); //check for what we are clicking on if (Physics.Raycast(ray, out hit)) { if (hit.transform.tag == "Object" && ConnectedBody == null) { ConnectedBody = hit.transform.gameObject.GetComponent <Rigidbody> (); ConnectedBody.useGravity = false; spring.connectedBody = ConnectedBody; spring.massScale = ConnectedBody.mass; lineRender.ToggleLine(true); } } } if (OVRInput.GetUp(OVRInput.Button.PrimaryIndexTrigger)) { //if we click when we have an object, drop it if (ConnectedBody != null) { ConnectedBody.useGravity = true; spring.connectedBody = null; ConnectedBody = null; lineRender.ToggleLine(false); return; } } //continually draw the line if (ConnectedBody != null && lineRender != null) { lineRender.SetDrawValues(this.transform.position, spring.transform.position, ConnectedBody.transform.position); lineRender.DrawCurve(); } }
// Update is called once per frame void Update() { //move spring farther and cloaser to the player if (OVRInput.Get(OVRInput.Button.DpadUp)) { spring.gameObject.transform.position = spring.gameObject.transform.position + (transform.forward * .1f); } if (OVRInput.Get(OVRInput.Button.DpadDown)) { spring.gameObject.transform.position = spring.gameObject.transform.position - (transform.forward * .1f); } if (OVRInput.Get(OVRInput.Button.PrimaryHandTrigger)) { //if we click when we have an object, drop it if (ConnectedBody != null) { ConnectedBody.useGravity = true; spring.connectedBody = null; ConnectedBody = null; lineRender.ToggleLine(false); return; } RaycastHit hit; Ray ray = new Ray(transform.position, transform.forward); //check for what we are clicking on if (Physics.Raycast(ray, out hit)) { if (hit.transform.tag == "Object" && ConnectedBody == null) { ConnectedBody = hit.transform.gameObject.GetComponent <Rigidbody> (); ConnectedBody.useGravity = false; spring.connectedBody = ConnectedBody; spring.massScale = ConnectedBody.mass; lineRender.ToggleLine(true); } } } //continually draw the line if (ConnectedBody != null && lineRender != null) { lineRender.SetDrawValues(this.transform.position, spring.transform.position, ConnectedBody.transform.position); lineRender.DrawCurve(); } }