/// <summary> /// Select the current item. If it's locked and we have enough money we unlock it. /// If it is already unlocked we play with the selected item. /// </summary> public void SelectItem() { // If the item is unlocked, select it and start the game if (items[currentItem].lockState == 1) { // Set this item as the player object gameController.playerObject = items[currentItem].itemIcon.GetComponent <ECCCar>(); // Start the game gameController.StartGame(); // Destroy the shop icon Destroy(currentIcon.gameObject); // Hide the shop camera if (shopCamera) { shopCamera.SetActive(false); } // Deactivate the shop object gameObject.SetActive(false); } else if (moneyLeft >= items[currentItem].price) { // Unlock the item items[currentItem].lockState = 1; // Set the lock state of the current item PlayerPrefs.SetInt(currentIcon.name, items[currentItem].lockState); // Deduct the price of the item from the money we have moneyLeft -= items[currentItem].price; // Save the money we have left PlayerPrefs.SetInt(moneyPlayerprefs, moneyLeft); //Update the text of the money we have moneyText.GetComponent <Text>().text = moneyLeft.ToString() + moneySign; // Create the unlock effect on the item if (unlockEffect) { Instantiate(unlockEffect, currentIcon.position, currentIcon.rotation); } // Set the item ChangeItem(0); } }
public void SelectItem() { if (items[currentItem].lockState == 1) { gameController.playerObject = items[currentItem].itemIcon.GetComponent <ECCCar>(); gameController.StartGame(); Destroy(currentIcon.gameObject); if (shopCamera) { shopCamera.SetActive(false); } gameObject.SetActive(false); } else if (moneyLeft >= items[currentItem].price) { items[currentItem].lockState = 1; PlayerPrefs.SetInt(currentIcon.name, items[currentItem].lockState); moneyLeft -= items[currentItem].price; PlayerPrefs.SetInt(moneyPlayerprefs, moneyLeft); moneyText.GetComponent <Text>().text = moneyLeft.ToString() + moneySign; if (unlockEffect) { Instantiate(unlockEffect, currentIcon.position, currentIcon.rotation); } ChangeItem(0); } }