public void RemoveFromInventory(UseableElement item) { //invButtons[inventory.IndexOf(item)].GetComponentInChildren<Image>().sprite = null; // invButtons[inventory.IndexOf(item)].interactable = false; inventory.Remove(item); UpdateButtons(); SetActiveElement(0); }
public void AddToInventory(UseableElement item) { inventory.Add(item); //invButtons[inventory.Count-1].GetComponentInChildren<Image>(); invButtons[inventory.Count - 1].GetComponentInChildren <Image>().sprite = item.icon; invButtons[inventory.Count - 1].interactable = true; if (item.objName != "hand") { item.gameObject.GetComponent <Collider2D>().enabled = false; item.gameObject.GetComponent <SpriteRenderer>().enabled = false; } }
void Update() //Wysyłanie raycasta z kursora na gre, { //jezeli jakikolwiek interaktywny element zostanie uderzony, aktywuje sie if (!forceFeed) { allowClick = true; } if (Input.GetMouseButtonDown(0) && allowClick) { Vector2 worldPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition); RaycastHit2D hit = Physics2D.Raycast(worldPoint, Vector2.zero); //If something was hit, the RaycastHit2D.collider will not be null. if (hit.collider != null && allowInteraction) { InteractivElement intItem = hit.collider.gameObject.GetComponent <InteractivElement>(); if (intItem != null) { if (intItem.isInteractive) { StartCoroutine(CountClick(intItem)); HintFeedback.lastClickedElement = intItem; // Debug.Log(HintFeedback.lastClickedElement.gameObject.name); intItem.OnClickBehaviour(); Inventory.Instance.SetActiveElement(0); } } UseableElement usblItem = hit.collider.gameObject.GetComponent <UseableElement>(); if (usblItem != null) { //if (UsblItem.isInteractive) //StartCoroutine(CountClick(usblItem)); Wait(); usblItem.PickUp(); } Zoom zoomItem = hit.collider.gameObject.GetComponent <Zoom>(); if (zoomItem != null) { zoomItem.ZoomIn(); } } } }
public void SetActiveElement(int i) { //Debug.Log(i); if (i < 6) { if (!inventory[i].interactive) { activeElement = inventory[i]; if (i != 0) { invButtons[0].GetComponentInChildren <Image>().sprite = invButtons[i].GetComponentInChildren <Image>().sprite; } else { invButtons[0].GetComponentInChildren <Image>().sprite = noItem; } if (i != 0) { Feedback.Instance.ShowText(activeElement.name, 0.5f, true); } } else if (inventory[i].feedbackOnlyUseable) { inventory[i].GiveFeedback(); } else //interactywny { GameObject b = GameObject.Find("BackButton"); if (b != null) { b.GetComponent <Button>().onClick.Invoke(); } inventory[i].OpenCloseUp(); activeElement = inventory[i]; } //Debug.Log(activeElement.objName); } }
protected override IEnumerator OnClickAction() { switch (actualState) { case States.UnBroken: // Debug.Log(Inventory.Instance.activeElement.objName); if (Inventory.Instance.activeElement.objName == "mlotek") { if (lupa.gameObject.active) { lupa.gameObject.SetActive(false); hand.gameObject.SetActive(true); } sequenceStarted = true; feedbackOnly = false; //mySpriteRenderer.sprite = avaibleSprites[1]; Feedback.Instance.ShowText("Aquarium broke whole! water is pouring out!", 2f, false); actualState = States.Broken; sequenceOn = true; Inventory.Instance.RemoveFromInventory(Inventory.Instance.activeElement); } else { Feedback.Instance.ShowText("There's glass on top", 1.5f, true); } break; default: if (Inventory.Instance.activeElement.objName == "net") { feedbackOnly = false; // actualState = States.PhaseOne; //isInteractive = false; hidenItems[0].PickUp(); hidenItems = new UseableElement[0]; hand.gameObject.SetActive(false); Feedback.Instance.ShowText("i need to dry these slides", 2f, false); Inventory.Instance.RemoveFromInventory(Inventory.Instance.activeElement); } else { if (hidenItems.Length < 1) { feedbackOnly = true; Feedback.Instance.ShowText("nothing else is here", 1.5f, true); } else { feedbackOnly = true; Feedback.Instance.ShowText("To far to reach by hand", 1.5f, true); } } break; /* * case States.PhaseTwo: * break; * case States.PhaseThree: * break; * case States.PhaseFour: * break; */ } return(base.OnClickAction()); }