private void InspectShopItems() { /*if (Input.GetKeyDown(KeyCode.Space)) * { * int shopItemsLayer = 9; //Layer of Selectable Shop Items * int layermask = (1 << shopItemsLayer); //Make sure the raycast only collides with the items in the shop * * //##Fix deze raycast * * Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); * RaycastHit hit; * if (Physics.Raycast(ray, out hit, Mathf.Infinity, layermask)) * { * ShopItemScript currentScript = hit.transform.gameObject.GetComponent<ShopItemScript>(); * currentScript.IsInspected = true; * * _inspectedItem = hit.transform.gameObject; * } * }*/ if (Input.GetKeyUp(KeyCode.Space)) { ShopItemScript currentScript = _inspectedItem.transform.gameObject.GetComponent <ShopItemScript>(); currentScript.IsInspected = false; } InspectItem(); }
void Update() { if (Input.mousePosition.x > 157 && Input.mousePosition.x < 780 && Input.mousePosition.y > 115 && Input.mousePosition.y < 467) { Ray ray = camera.ScreenPointToRay(Input.mousePosition); foreach (var item in Physics.RaycastAll(ray, 1000)) { if (item.collider.gameObject.name == "Button") { Select = item.collider.gameObject.transform.parent.GetComponent<ShopItemScript>(); } } if (Input.GetButtonDown("Fire1")) { StartDrag = Input.mousePosition; } if (Input.GetButtonUp("Fire1")) { if (Vector3.Distance(StartDrag, Input.mousePosition) < 2) { Select.ClickButton(null); } } } else { Select = null; } }
private void OnButtonPress(ShopItemScript item) { openBuyPanel(item.itemName, item.itemCost, item.itemImage); disItemName = item.itemName; disItemID = item.itemId; disItemCost = item.itemCost; }
//Script is used by shop confirmation panel //Function is called when window loads public void SetupPanel(ShopItemScript itemScript) { myItemScript = itemScript; MyItem = itemScript.MyItem; SetupPreview(); QuestionText.text = "Are you sure you want to buy " + MyItem.itemName + " for " + MyItem.itemPrice + "$?"; }
// Use this for initialization void Start() { GameObject spawnedItem = CubyGameManager.GetInstance().SpawnItem(transform.position); //add cost script ShopItemScript script = (ShopItemScript)spawnedItem.AddComponent(typeof(ShopItemScript)); script.Cost = Random.Range(10, 50); }
private void ChangeCharacter(ShopItemScript sender) { for (int i = 0; i < gameObject.transform.childCount; i++) { transform.GetChild(i).transform.gameObject.SetActive(false); } transform.GetChild(sender.index).gameObject.SetActive(true); }
public static void SaveShop(ShopItemScript shopItemScript) { BinaryFormatter formatter = new BinaryFormatter(); string path = Application.persistentDataPath + "/shop.save"; FileStream stream = new FileStream(path, FileMode.Create); ShopData data = new ShopData(shopItemScript); formatter.Serialize(stream, data); stream.Close(); }
private void InspectItem() { if (_inspectedItem == null) { return; } ShopItemScript currentScript = _inspectedItem.GetComponent <ShopItemScript>(); if (currentScript.IsInspected) { //Insert behaviour when inspecting the item } }
private void DeSelectItem(GameObject currentObject) { ShopItemScript currentScript = currentObject.GetComponent <ShopItemScript>(); currentScript.IsSelected = false; if (currentScript.TotalSelected > 0) { currentScript.TotalSelected--; currentScript.InStock++; SelectedItems.Remove(currentObject); TotalPriceToPay -= currentScript.ThisPrice; } }
private void SetAsDefault(ShopItemScript item) { foreach (GameObject obj in shoppingItems) { if (obj.transform != transform) { obj.GetComponent <ShopItemScript>().Reset(); } } playerdata.defaultCharacter = item.index; item.SetImageToSelected(); playerdata.Save(); }
// Use this for initialization void Start() { shoppingItems = GameObject.FindGameObjectsWithTag("ShopItem"); ShopItemScript.OnSetAsDefault += SetAsDefault; foreach (ShopItemScript shopitem in GetComponentsInChildren <ShopItemScript>()) { if (shopitem.index == playerdata.defaultCharacter) { defaultCharacter = shopitem; } } SetAsDefault(defaultCharacter); }
private void SelectItem(GameObject currentObject) { ShopItemScript currentScript = currentObject.GetComponent <ShopItemScript>(); currentScript.IsSelected = true; GameObject inventorySlot = Instantiate(this._inventorySlot); InventoryList.Add(inventorySlot); inventorySlot.transform.position += new Vector3((InventoryList.Count - 1) % 2 * 100, (InventoryList.Count - 1) / 2 * 100, 0); inventorySlot.GetComponent <Image>().sprite = currentObject.GetComponent <Image>().sprite; if (currentScript.InStock > 0) { currentScript.InStock--; currentScript.TotalSelected++; SelectedItems.Add(currentObject); TotalPriceToPay += currentScript.ThisPrice; } }
private void Start() { StartCoroutine(getUserInfo()); for (int i = 0; i < shopItemA.Length; i++) { ShopItemScript si = shopItemA[i]; //shop item from array StartCoroutine(checkItem()); //checkItem IEnumerator checkItem() { WWWForm form = new WWWForm(); form.AddField("userid", DBManager.userid); form.AddField("itemid", si.itemId); using (UnityWebRequest www = UnityWebRequest.Post("http://learnplusultra.xyz/app_scripts/checkrewards.php", form)) { yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); SceneManager.LoadScene("Log_In"); } else { string text = www.downloadHandler.text; //Debug.Log(www.downloadHandler.text); Debug.Log(si.itemId + " " + text); if (text != null) { if (text == "exists") { // si.alreadyBought = true; // Debug.Log(si.itemName + "-" +si.alreadyBought); } else { GameObject itemObject = Instantiate(shopItemPrefab, shopContainer); //access button function itemObject.GetComponent <Button>().onClick.AddListener(() => OnButtonPress(si)); //change sprite alpha itemObject.transform.GetChild(0).GetComponent <Image>().sprite = si.itemImage; } } else { //SceneManager.LoadScene("Log In"); Debug.Log("Try again"); } } } } } // PopulateShop(); }
public ShopData(ShopItemScript shopItemScript) { amount = shopItemScript.amountOf; amountOfItems = shopItemScript.itemAmount; }
//Function loads up a shop subwindow, with all the items of a certain type public void OpenSubwindow(string subShopText) { SubShop subShop; if (subShopText.Equals(SubShop.BGColors.ToString())) { subShop = SubShop.BGColors; } else if (subShopText.Equals(SubShop.PlayerTitle.ToString())) { subShop = SubShop.PlayerTitle; } else if (subShopText.Equals(SubShop.MemePackage.ToString())) { subShop = SubShop.MemePackage; } else { subShop = SubShop.PlayerTitle; } //Clear children int itemsCount = 0; foreach (Transform child in ShopItemsGrid.transform) { GameObject.Destroy(child.gameObject); } ShopItemScript DefaultItem = null; ShopItemScript EquippedItem = null; //Begin instantiating display items into panel for (int i = 0; i < shopItems.Count; i++) { if (shopItems[i].itemType == subShop) { itemsCount++; GameObject newButton = Instantiate(ShopItemButtonPrefab, ShopItemsGrid.transform); newButton.GetComponent <ShopItemScript>().SetButtonProperties(shopItems[i], ConfirmationPanel, this); if (newButton.GetComponent <ShopItemScript>().IsEquippedItem()) { EquippedItem = newButton.GetComponent <ShopItemScript>(); } if (itemsCount == 1) { DefaultItem = newButton.GetComponent <ShopItemScript>(); } } } //If no item is equipped, equip the first item which is supposed to be equipped by default if (EquippedItem == null) { if (DefaultItem != null) { DefaultItem.Owned = true; DefaultItem.EquipLocally(); } } //Alter UI elements accordingly ShopItemsGrid.GetComponent <RectTransform>().sizeDelta = new Vector2(ShopItemsGrid.GetComponent <RectTransform>().sizeDelta.x, (ShopItemsGrid.cellSize.y + ShopItemsGrid.spacing.y) * Mathf.Clamp(Mathf.CeilToInt((float)itemsCount / 3.0f), 1, itemsCount)); ShopItemsGrid.GetComponent <RectTransform>().anchoredPosition = new Vector2(ShopItemsGrid.GetComponent <RectTransform>().anchoredPosition.x, 0); //Edit displayed text switch (subShop) { case SubShop.BGColors: ShopPanelTitle.text = "Background colors"; ShopPanelSubtext.text = "Pick a background color for matches"; break; case SubShop.PlayerTitle: ShopPanelTitle.text = "Player titles"; ShopPanelSubtext.text = "Pick a player title"; break; case SubShop.MemePackage: ShopPanelTitle.text = "Meme packages"; ShopPanelSubtext.text = "Pick a meme package to enhance your game!"; break; } }