void ShootWater() { if (waterAmmoClip > 0) { //Debug.Log ("Shooting water!"); waterAmmoClip--; RaycastHit hit = new RaycastHit(); // raycast if (Physics.Raycast(this.transform.position, transform.TransformDirection(Vector3.forward), out hit, waterRange)) { // used to change variable that shows up UI ExtinguishObject extinguishObject = GameObject.Find("Human").GetComponent <ExtinguishObject> (); // if the player shot flamable object that is on fire if (hit.collider.gameObject.tag == "Flamable") { ItemScript itemScript = hit.collider.gameObject.GetComponent <ItemScript> (); Debug.Log("Raycasted flamable object: " + hit.collider.name); // used to show up UI elements, when the player points at fired object if (itemScript.onFire && extinguishObject != null) { // adding steam effect steamEffect = Instantiate(Resources.Load("Prefabs/Steam"), itemScript.transform.position, Quaternion.identity) as GameObject; extinguishObject.raycastedFire = true; // passing the amount of water to itemscript itemScript.amountOfWater += waterAmount; Debug.Log("Amount Filled " + itemScript.amountOfWater); } else { extinguishObject.raycastedFire = false; } } else if (extinguishObject != null) // checking first if the object was found { extinguishObject.raycastedFire = false; } } // end of Physics.Raycast } // end of waterAmmoClip > 0 }
public bool objectCollided = false; // checks if the carried object has touched a wall // Update is called once per frame void Update() { float dist = Vector3.Distance(gameObject.transform.position, player.transform.position); //Debug.Log("Distance to object " + transform.name + " is " + dist); ExtinguishObject extObjScript = player.gameObject.GetComponent <ExtinguishObject>(); // if the player is close enough to the object if (dist <= 26.0f && extObjScript.currentWeapon == 0) { ableToPickObject = true; eraseUI = false; humanUI.text = "Press B button to pick up " + gameObject.name + " object."; } else { // erasing the UI text if (!(eraseUI)) { humanUI.text = ""; } eraseUI = true; ableToPickObject = false; } // if able to pick the object up and user presses B button if (ableToPickObject && Input.GetButtonDown("C1B")) { objectCarried = true; } // while the object is being carried if (objectCarried) { transform.position = objectHolder.transform.position; humanUI.text = "Press B button to throw the object or Y to leave it."; // if object collides with something it drops out of player's hands if (objectCollided) { objectCarried = false; objectCollided = false; humanUI.text = ""; } // when the player presses X button if (Input.GetButtonDown("C1B")) { transform.parent = null; objectCarried = false; // adding force to the object GetComponent <Rigidbody>().AddForce(playerCam.forward * throwForce); humanUI.text = ""; } // droping the object from hands if (Input.GetButtonDown("C1Y")) { transform.parent = null; objectCarried = false; humanUI.text = ""; } } }