public void OnInteraction() { Debug.Log("OnInteraction triggered!"); // If the platform currently is locked, we don't want to activate it/or deactivate it. if (IsLocked) { return; } // When the platform currently is activated, an additional click should deactivate it; // If the platform currently is not activated, we want to activate it for rotation. IsActivated = !IsActivated; // Notify all event listeners via the game logic controller _glc.NotifyDisabledInputs(IsActivated); if (IsActivated) { // If using the accelerometer, we need a baseTilt value to compute the difference if (accelerometerEnabled) { baseTilt = Input.acceleration; } // Search all rotatable objects by tag foreach (GameObject item in GameObject.FindGameObjectsWithTag(_rotTag)) { if (item != this.gameObject) { item.GetComponent <RotateablePlatform>().IsActivated = false; Outline outline = item.GetComponent <Outline>(); if (outline == null) { outline = item.GetComponentInChildren <Outline>(); } } } } // Mark current object by outline outlineEffect.enabled = IsActivated; }
private void Update() { if (Input.GetMouseButtonDown(0)) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); // We don't want to detect a raycast hit when we click on the ui elements // see for touch difficulties https://answers.unity.com/questions/895861/ui-system-not-blocking-raycasts-on-mobile-only.html if (!IsPointerOverUIObject() && Physics.Raycast(ray, out hit, rayCastDistance)) // or whatever range, if applicable { GameObject go = hit.transform.gameObject; // if the hit gameobject or its parent (empty to fix right handed coordinate system) got tag rotateable if (go.tag == "Rotateable") { go.GetComponent <RotateablePlatform>().OnInteraction(); } else if (go.transform.parent.tag == "Rotateable") { go.GetComponentInParent <RotateablePlatform>().OnInteraction(); } } else if (!_cameraIsMoving) { //Debug.Log(GameObject.FindGameObjectsWithTag("Rotateable").Length); foreach (GameObject item in GameObject.FindGameObjectsWithTag("Rotateable")) { item.GetComponent <RotateablePlatform>().IsActivated = false; Outline outline = item.GetComponent <Outline>(); if (outline == null) { outline = item.GetComponentInChildren <Outline>(); } outline.enabled = false; } _glc.NotifyDisabledInputs(false); } } }