/// <summary> /// Activates the lock and starts the lock game /// </summary> /// <param name="activatorSource"></param> public void Activate(LPLockActivator activatorSource) { // Keep track of the activator so we can deactivate it later if (activatorSource) { activator = activatorSource; } // Reset the round count. This is for example when you start playing and then abort the game, when you play again the round starts from 1 roundsCount = 1; // Reset the mistakes count mistakesCount = 0; // If the sequence is not preset, disable the buttons and add a note to it if (sequence.Length <= 0) { // Deactivate all the dial buttons so the player can't interact with them while the sequence is playing for (index = 0; index < dialButtons.Length; index++) { dialButtons[index].interactable = false; } // Add a note AddNote(); } else { // Activate all the dial buttons so the player can interact with them again for (index = 0; index < dialButtons.Length; index++) { dialButtons[index].interactable = true; } } // Show the first round on the screen text if (screenText) { // If the game has just one round, don't display a number next to the round message if (rounds <= 1) { screenText.text = roundMessage; } else { screenText.text = roundMessage + sequence.Length; } } }
/// <summary> /// Activates the lock and starts the lock game /// </summary> /// <param name="activatorSource"></param> public void Activate(LPLockActivator activatorSource) { // Keep track of the activator so we can deactivate it later if (activatorSource) { activator = activatorSource; } // If we are not using a mobile device, hide the cylinder rotation buttons if (!Application.isMobilePlatform) { if (GameObject.Find("MobileColorIndicator")) { GameObject.Find("MobileColorIndicator").SetActive(false); } if (GameObject.Find("ButtonRotate")) { GameObject.Find("ButtonRotate").SetActive(false); } } if (GameObject.Find("Sweetspot")) { // Hold the sweetspot object for quicker access sweetspot = GameObject.Find("Sweetspot").GetComponent <RectTransform>(); // Hide the image component from the sweetspot ( the red do we use to set the size in the editor ) sweetspot.GetComponent <Image>().enabled = false; } // Calculate the minimum sweetspot range, so that it's never exactly in the center float minimumRange = Mathf.Min(lockpick.sizeDelta.x * GetComponent <RectTransform>().localScale.x * 0.5f, lockpick.sizeDelta.y * GetComponent <RectTransform>().localScale.y * 0.5f); // Calculate the maximum sweetspot range based on the cylinder size cylinderSize = Mathf.Min(cylinder.sizeDelta.x * GetComponent <RectTransform>().localScale.x, cylinder.sizeDelta.y * GetComponent <RectTransform>().localScale.y); // Choose a random spot within the cylinder area float positionX = Random.Range(cylinder.position.x - cylinder.sizeDelta.x * GetComponent <RectTransform>().localScale.x * 0.5f, cylinder.position.x + cylinder.sizeDelta.x * GetComponent <RectTransform>().localScale.x * 0.5f); float positionY = Random.Range(cylinder.position.y - cylinder.sizeDelta.y * GetComponent <RectTransform>().localScale.y * 0.5f, cylinder.position.y + cylinder.sizeDelta.y * GetComponent <RectTransform>().localScale.y * 0.5f); // Set the sweetspot position sweetspot.position = new Vector2(positionX, positionY); // Limit the sweetspot position to a circular area within the cylinder sweetspot.position = cylinder.position + (sweetspot.position - cylinder.position).normalized * Random.Range(minimumRange, cylinderSize * 0.5f); }
/// <summary> /// Activates the lock and starts the lock game /// </summary> /// <param name="activatorSource"></param> public void Activate(LPLockActivator activatorSource) { // Keep track of the activator so we can deactivate it later if (activatorSource) { activator = activatorSource; } // If we are not using a mobile device, hide the cylinder rotation buttons if (!Application.isMobilePlatform) { if (GameObject.Find("MobileColorIndicator")) { GameObject.Find("MobileColorIndicator").SetActive(false); } if (GameObject.Find("ButtonRotate")) { GameObject.Find("ButtonRotate").SetActive(false); } } // Set a random sweetspot center, sweetspotAngle = Random.Range(0, 180); }