Quantcast
Channel: Questions in topic: "attach"
Viewing all articles
Browse latest Browse all 168

How to have attach and detach Fixed Joints on objects with UI button through Oculus?,How to break fixed joint in a command?

$
0
0
I created a UI Button with the purpose to turn objects into fixed joints whenever is pressed. I want a script where I can press A with the oculus controller over the UI Button and make the cubes join, and I want to press X with the oculus controller over the UI Button to break the joints of the objects. But this is not working for me so far, please any suggestions? using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Attach : MonoBehaviour { public GameObject cube; public Text attachText; private FixedJoint joint; private float breakForce; void ClickUIButton() { if(attachText.enabled == true) //OVRInput.GetDown(OVRInput.Button.One) { if(OVRInput.GetDown(OVRInput.Button.One)) { join(); } if(OVRInput.GetDown(OVRInput.Button.Three)) { Destroy(); } } } private void join() { gameObject.AddComponent(); gameObject.GetComponent().connectedBody = cube.GetComponent(); //joint = GetComponent(); } private void Destroy() { if (gameObject.GetComponent().breakForce == Mathf.Infinity) { Destroy(gameObject.GetComponent()); } } } ,I created a UI button, and when I press A on the oculus controller over the UI button I want to make the cubes have a fixed joint without detaching, and when I press X on the controller over the UI button I want the objects to break joints. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Attach : MonoBehaviour { public GameObject cube; public Text attachText; private FixedJoint joint; private float breakForce; void ClickUIButton() { if(attachText.enabled == true) //OVRInput.GetDown(OVRInput.Button.One) { if(OVRInput.GetDown(OVRInput.Button.One)) { join(); } if(OVRInput.GetDown(OVRInput.Button.Three)) { Destroy(); } } } private void join() { gameObject.AddComponent(); gameObject.GetComponent().connectedBody = cube.GetComponent(); //joint = GetComponent(); } private void Destroy() { if (gameObject.GetComponent().breakForce == Mathf.Infinity) { Destroy(gameObject.GetComponent()); } } }

Viewing all articles
Browse latest Browse all 168

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>