void RpcKeyDestroy_(int id) { GameObject[] items = GameObject.FindGameObjectsWithTag("Item"); foreach (GameObject item in items) { if (item.GetComponent <ItemInformation>().number == id) { KeySpawn Item_Manager = GameObject.Find("SpawnManager").GetComponent <KeySpawn>(); Item_Manager.keySpawnPos.Add(item.transform.position); Destroy(item); break; } } }
void Awake() { Spawner = GameObject.Find("KeySpawnPoint").transform; if (m_Instance != null) { Debug.LogError("More than one GameManager in scene"); } else { m_Instance = this; } for (int i = 0; i < Spawner.childCount; i++) { keySpawnPos.Add(Spawner.GetChild(i).position); } }
void Update() { RaycastHit hit; if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, 3)) { Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow); if (PickCheck(hit)) { pickUpText.enabled = true; switch (hit.collider.GetComponent <Items_Identity>().interaction) { case Items_Identity.itemType.pick: if (Input.GetKeyDown(KeyCode.E)) { _audioSource.Play(); switch (hit.collider.GetComponent <Items_Identity>().retrieveValue) { case "battery": _pBat.RefillBattery(); break; case "c_envy": _audioSource.PlayOneShot(thunder); hit.collider.gameObject.GetComponent <CrystalSpawner>().SpawnCrystals(); hit.collider.gameObject.GetComponent <CrystalSpawner>().SpawnGuardians(); _pInventory.getItem(getItemID(hit.collider.gameObject)); break; default: _pInventory.getItem(getItemID(hit.collider.gameObject)); break; } Destroy(hit.collider.gameObject); } pickUpText.text = "Pick up " + "<" + hit.collider.gameObject.GetComponent <Items_Identity>().identity + ">"; break; case Items_Identity.itemType.open: if (Input.GetKeyDown(KeyCode.E)) { string neededKey = hit.collider.GetComponent <Items_Identity>().requiredKey; for (int i = 0; i < _pInventory.items.Count; i++) { if (_pInventory.items[i].Equals(neededKey)) { Animator anim = hit.collider.gameObject.transform.root.GetComponent <Animator>(); anim.SetTrigger("open"); } else { _audioSource.PlayOneShot(unknownAction); } } } pickUpText.text = "Open " + "<" + hit.collider.gameObject.GetComponent <Items_Identity>().identity + ">"; break; case Items_Identity.itemType.use: if (Input.GetKeyDown(KeyCode.E)) { switch (hit.collider.GetComponent <Items_Identity>().retrieveValue) { case "d_pallet": for (int i = 0; i < _pInventory.items.Count; i++) { if ( _pInventory.items[i].Equals("c_envy") ^ _pInventory.items[i].Equals("c_gluttony") ^ _pInventory.items[i].Equals("c_pride") ^ _pInventory.items[i].Equals("c_greed") ^ _pInventory.items[i].Equals("c_lust") ^ _pInventory.items[i].Equals("c_wrath") ) { CrystalPallet c_Insert = hit.collider.gameObject.GetComponent <CrystalPallet>(); c_Insert.CrystalInsert(_pInventory.items[i]); _pInventory.items.RemoveAt(i); } else { _audioSource.PlayOneShot(unknownAction); } } break; } } pickUpText.text = "Use " + "<" + hit.collider.gameObject.GetComponent <Items_Identity>().identity + ">"; break; case Items_Identity.itemType.destroy: pickUpText.text = "Destroy " + "<" + hit.collider.gameObject.GetComponent <Items_Identity>().identity + ">"; break; case Items_Identity.itemType.read: if (Input.GetKeyDown(KeyCode.E)) { if (!_isReading) { notePaper.texture = hit.collider.gameObject.GetComponent <Items_Identity>().noteImage; notePaper.gameObject.SetActive(true); Player_Controller.instance.canMove = false; if (hit.collider.gameObject.name.Equals("Note_ruins2")) { KeySpawn keys = hit.collider.gameObject.GetComponent <KeySpawn>(); keys.SpawnKeys(); } } else { notePaper.gameObject.SetActive(false); Player_Controller.instance.canMove = true; } _isReading = !_isReading; } pickUpText.text = "Read " + "<" + hit.collider.gameObject.GetComponent <Items_Identity>().identity + ">"; break; } } else { pickUpText.enabled = false; } } else { pickUpText.enabled = false; } }