/// <summary> /// Place right hand on selected object /// </summary> public void PlaceRightHand() { GameObject go = selectObject.GetObject(); Vector3 hitPoint = selectObject.GetHitPoint(); Vector3 hitPointNormal = selectObject.GetHitPointNormal(); selectObject.ResetColor(); if (go != null) { if (!HandChecker.HasRightHand(go) && !HandChecker.IsAnyHand(go)) { if (go.GetComponent <Rigidbody>() != null) { //Destroy the RigidBody Destroy(go.GetComponent <Rigidbody>()); //_hasRigidBody = true; } Vector3 rotationRight = new Vector3(); //load rightHandPrefab and instantiate it with the predetermined parameters GameObject rightHandPrefab = Resources.Load("HandPrefab" + Path.DirectorySeparatorChar + "RightHand") as GameObject; GameObject rightHand = Instantiate(rightHandPrefab, hitPoint + selectObject.GetDragAndRotate().GetOffsetAfterDrag() + hitPointNormal * OffSetValue, Quaternion.Euler(rotationRight)); rightHand.transform.SetParent(go.transform); rightHand.transform.rotation = Quaternion.FromToRotation(-rightHand.transform.right, hitPointNormal); //Add a BoxCollider to the hand _boxColliderRightHand = rightHand.AddComponent <BoxCollider>(); adjustBoxCollider(_boxColliderRightHand, 1); } } }
/// <summary> /// Toggles remove button and Create Target button /// </summary> /// <param name="go">Selected game object</param> public void ObjectSelected(GameObject go) { // If no object is selected (e.g. click on background) if (go is null) { objectSelectedBar.SetActive(false); return; } // Show all buttons in bar ShowButtons(); //Check if moveTarget has not been already created if (selectObject.GetObject().transform.Find("moveTarget") || MoveTargetChecker.IsMoveTarget(selectObject.GetObject()) || HandChecker.IsAnyHand(selectObject.GetObject())) { createTargetButton.SetActive(false); } //Hide button if walk target already created if (selectObject.GetObject().transform.Find("WalkTarget") || selectObject.GetObject().transform.name.Equals("WalkTarget") || HandChecker.IsAnyHand(selectObject.GetObject())) { createWalkTargetButton.SetActive(false); } //Remove all onCLick Listener of previously clicked objects removeButton.GetComponent <Button>().onClick.RemoveAllListeners(); // Add click listener on remove button removeButton.GetComponent <Button>().onClick.AddListener(() => { //_parent is needed to add rigidbody after hands are removed // if (HandChecker.IsAnyHand(go)) _parent = go.transform.parent.gameObject; GameObject.Find("Main Camera").GetComponent <SelectObject>().ResetColor(); Destroy(go); //Add rigidbody if hands are removed /* * if (_parent != null )//&& GameObject.Find("Scene").GetComponent<PlaceHandsMenu>().GetRigidBody()) * { * if (!(HandChecker.HasLeftHand(_parent) && HandChecker.HasRightHand(_parent))) * { * _parent.AddComponent<Rigidbody>(); * } * } */ //Hide button removeButton.SetActive(false); }); }