private void OnTriggerEnter(Collider other) { if (other.tag == "Player" || other.tag == "Wall") { if (other.tag == "Player") { other.GetComponent <FirstPersonController>().gotHit = true; flashLight.GetComponent <Flashlight>().currentBattery--; flashlightUI.SetBatteryLevel(flashLight.GetComponent <Flashlight>().currentBattery); } Debug.Log("Destroy"); Destroy(transform.gameObject); } }
void OnTriggerStay(Collider other) { showText = true; if (!safeRemove) { if (Input.GetKeyUp(KeyCode.E)) { mainBattery = Flight.GetComponent <Flashlight>().currentBattery; Batteries = 1; other.GetComponent <FirstPersonController>().pickedItemUp = true; Flight.GetComponent <Flashlight>().currentBattery = Batteries + mainBattery; flashlightUI.SetBatteryLevel(Flight.GetComponent <Flashlight>().currentBattery); safeRemove = true; if (safeRemove) { Destroy(this.gameObject); } } } }
void minusBattery(int battery) { currentBattery -= battery; flashlightUI.SetBatteryLevel(currentBattery); }