void Run() { Transform interactableObject = m_coolingElement.transform.parent; // this is the gameobject which needs rotation, ... // get server rotation (which is the parent from this object) Transform server = this.transform.parent.parent; InteractableItem interactableItem = interactableObject.GetComponent <InteractableItem>(); Vector3 eulerAngles = interactableItem.transform.eulerAngles; eulerAngles.x = 270.0f; eulerAngles.y = 180.0f; // IF SERVER ROT-Y is 0 THEN 0 ELSE 180 eulerAngles.z = 0.0f; interactableItem.transform.eulerAngles = eulerAngles; Vector3 newPos = this.transform.GetChild(0).position; newPos.y += 0.5f; // offset interactableItem.transform.position = newPos; // set serverDoor kinematic //this.transform.parent.parent.gameObject.GetComponent<Rigidbody>().isKinematic = true; // rigidbody movement Rigidbody rigidbody = interactableItem.GetComponent <Rigidbody>(); rigidbody.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionZ; //this.gameObject.GetComponent<ServerCoolingElement>().enabled = false; }
private void DetectObjectHitLabel() { InteractableItem currentHitObject = hitInteractable.GetComponent <InteractableItem>(); //Detect what is hit with the ray, Can be a menu, arrows or an item. if (currentHitObject != null) { if (currentHitObject.isMenuItem) { prefab = (GameObject)Instantiate(currentHitObject.worldPrefab, transform.position, Quaternion.Euler(0, 0, 0)); //Spawn it at the controllers pos and with 0 rotation (facing upwards) interactingItem = prefab.GetComponent <InteractableItem>(); //Is only used for letting an object go again in this case interactingItem.BeginInteraction(this); Debug.Log(interactingItem); } else if (currentHitObject.isArrow) { currentHitObject.GetComponent <Arrows>().pressed = true; interactingItem = null; } else { interactingItem = currentHitObject; } if (interactingItem) //Starts interacting with the chosen item { if (interactingItem.IsInteracting()) //this statement is used in order to grap an item in the other hand { interactingItem.EndInteraction(this, false); } interactingItem.BeginInteraction(this); } } }
private void grabBrick() { // Check if flystick is inside a brick GameObject[] bricks = GameObject.FindGameObjectsWithTag("Brick"); GameObject selectedItem = null; foreach (GameObject brick in bricks) { if (brick.GetComponent <Collider>().bounds.Contains(flyStickInteraction.transform.position)) { selectedItem = brick; break; } } // Check if flystick points on a brick if (selectedItem == null) { flyStickInteraction.sendRayForBlocks(); selectedItem = flyStickInteraction.SelectedPart; } if (selectedItem) { interactingItem = selectedItem.GetComponent <InteractableItem>(); if (interactingItem) { GameObject towerObject = GameObject.Find("DynamicTower"); if (towerObject) { TowerInteractivity tower = towerObject.GetComponent <TowerInteractivity>(); if (interactingItem.name.Contains(TowerInteractivity.MaxRow.ToString()) && interactingItem.GetComponent <Renderer>().material.color != Color.green) { //return; } if (interactingItem.GetComponent <Renderer>().material.color != Color.green) { if (tower.FirstSelected == null) { tower.select(interactingItem.transform.gameObject); Debug.Log("select: " + interactingItem.transform.gameObject.name); } else { return; } } } if (interactingItem.isInteracting()) { interactingItem.EndInteraction(flyStickInteraction); interactingItem = null; Debug.Log("endInteraction"); } interactingItem.BeginInteraction(flyStickInteraction); } } }
private void Update() { if (enable) { if (InputSynchronizer.GetKeyDown("space")) { float minDistance = float.MaxValue; float distance; foreach (InteractableItem item in objectsHoveringOver) { distance = (item.transform.position - transform.position).sqrMagnitude; if (distance < minDistance) { minDistance = distance; closestItem = item; } } interactingItem = closestItem; closestItem = null; GameObject towerObject = GameObject.Find("DynamicTower"); if (towerObject != null && interactingItem != null) { TowerInteractivity tower = towerObject.GetComponent <TowerInteractivity>(); if (interactingItem.name.Contains(TowerInteractivity.MaxRow.ToString()) && interactingItem.GetComponent <Renderer>().material.color != Color.green) { return; } if (interactingItem.GetComponent <Renderer>().material.color != Color.green) { if (tower.FirstSelected == null) { tower.select(interactingItem.transform.gameObject); } else { return; } } } if (interactingItem) { if (interactingItem.isInteracting()) { interactingItem.EndInteraction(this); } interactingItem.BeginInteraction(this); } } if (InputSynchronizer.GetKeyUp("space") && interactingItem != null) { interactingItem.EndInteraction(this); } } }
/// <summary> /// Adds a interactable item to the hashmap if collision happens between itself and the controller /// </summary> private void OnTriggerEnter(Collider collider) { InteractableItem item = collider.GetComponent <InteractableItem>(); if (item) { m_objectsHoveringOver.Add(item); if (m_interactionItem != item) { item.GetComponent <Renderer>().material.SetColor("_Color", Color.cyan); } //Debug.Log("Adding gameobject: " + item.gameObject.name); } }
void Run(GameObject a_hdd) { Transform interactableObject = a_hdd.transform.parent; // this is the gameobject which needs rotation, ... // get server rotation (which is the parent from this object) Transform server = this.transform.parent.parent; InteractableItem interactableItem = interactableObject.GetComponent <InteractableItem>(); Vector3 newPos = this.transform.GetChild(0).position; interactableItem.transform.position = newPos; interactableItem.transform.LookAt(2 * interactableItem.transform.position - m_lookAt.transform.position); // adjust rigidbody movement Rigidbody rigidbody = interactableItem.GetComponent <Rigidbody>(); rigidbody.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionY; }
/// <summary> /// Removes a interactable item to the hashmap if collision is left between itself and the controller /// </summary> private void OnTriggerExit(Collider collider) { InteractableItem item = collider.GetComponent <InteractableItem>(); if (item) { //if (item == m_interactionItem) //{ // if (m_interactionItem.IsInteracting() == false) // { // m_objectsHoveringOver.Remove(item); // } //} m_objectsHoveringOver.Remove(item); if (m_interactionItem != item) { item.GetComponent <Renderer>().material.SetColor("_Color", Color.red); } //Debug.Log("Removing gameobject: " + item.gameObject.name); } }
// Update is called once per frame void Update() { if (controller == null) { Debug.Log("Controller not initialized"); return; } if (controller.GetPressDown(triggerButton)) { triggerDown = true; } if (controller.GetPressUp(triggerButton)) { triggerDown = false; } if (controller.GetPressDown(menuButton)) { AR.toggleAR(); } if (controller.GetPressDown(triggerButton)) { float minDistance = float.MaxValue; float distance; foreach (InteractableItem item in objectsHoveringOver) { if (item == null) { objectsHoveringOver.Remove(item); } else { distance = (item.transform.position - transform.position).sqrMagnitude; if (distance < minDistance) { minDistance = distance; closestItem = item; } } } interactingItem = closestItem; if (interactingItem) { if (interactingItem.IsInteracting()) { interactingItem.EndInteraction(this); } interactingItem.BeginInteraction(this); } } if (controller.GetPress(triggerButton) && interactingItem != null) { if (controller.GetPressDown(gripButton) && interactingItem.GetComponent <ProductController>() != null) { interactingItem.EndInteraction(this); objectsHoveringOver.Remove(interactingItem); cart.fastAddToCart(interactingItem.GetComponent <ProductController>()); interactingItem = null; } } if (controller.GetPressUp(triggerButton) && interactingItem != null) { if (ARobjGrabbed) { interactingItem.GetComponent <BoxCollider>().isTrigger = true; ARobjGrabbed = false; } interactingItem.EndInteraction(this); objectsHoveringOver.Remove(interactingItem); interactingItem = null; } if (controller.GetPressDown(gripButton)) { if (AR.getActiveStatus()) { AR.setWand(this); AR.gripButtonPressed(true); } } if (controller.GetPressUp(gripButton)) { AR.gripButtonPressed(false); } }
// Update is called once per frame void Update() { if (controller == null) { Debug.Log("Controller not initialized"); return; } else { if (controller.GetPressDown(triggerButton)) { float minDistance = float.MaxValue; float distance; foreach (InteractableItem item in objectsHoveringOver) //Goes through all the objects and detects which is closest to the controller { distance = (item.transform.position - transform.position).sqrMagnitude; if (distance < minDistance) { minDistance = distance; closestItem = item; } } if (closestItem != null && closestItem.isMenuItem) //If the item pressed is something on the menu, then instantiate an object corresponding to the one on the menu { prefab = (GameObject)Instantiate(closestItem.worldPrefab, transform.position, Quaternion.Euler(0, 0, 0)); //Spawn it at the controllers pos and with 0 rotation (facing upwards) interactingItem = prefab.GetComponent <InteractableItem>(); //Is only used for letting an object go again in this case closestItem = null; interactingItem.BeginInteraction(this); } else if (closestItem != null && closestItem.isArrow) //If an arrow is pressed. simply tell the arrow and make it change menu page { closestItem.GetComponent <Arrows>().pressed = true; interactingItem = null; closestItem = null; } else { interactingItem = closestItem; closestItem = null; } if (interactingItem) //Starts interacting with the chosen item { if (interactingItem.IsInteracting()) //this statement is used in order to grap an item in the other hand { interactingItem.EndInteraction(this, false); } interactingItem.BeginInteraction(this); } } if (controller.GetPressUp(triggerButton) && interactingItem != null) { interactingItem.EndInteraction(this, false); //Stops interaction with the item held interactingItem = null; } } if (interactingItem != null) { if (controller.GetPressDown(menuButton) && !interactingItem.isMenuItem && !interactingItem.isArrow) { objectsHoveringOver.Clear(); closestItem = null; interactingItem.EndInteraction(this, true); interactingItem = null; } } //if the controller has the menu attached then we can disable/enable the menu with that controller by pressing the Touch Pad if (controller.GetPressDown(padButton) && changeMenu == false && controller.index == 2) { isMenuActive = !isMenuActive; changeMenu = true; Menu(isMenuActive); } }