void ThrowWaterBomb() { WaterBombScript waterBombScript = waterBomb.GetComponent <WaterBombScript> (); if (waterBombScript.numberOfBombs > 0) { waterBombScript.numberOfBombs--; GameObject bomb = Instantiate(Resources.Load("Prefabs/Water-Bomb"), waterBomb.transform.position, Quaternion.identity) as GameObject; bomb.GetComponent <Rigidbody> ().AddForce(transform.forward * throwForce, ForceMode.Impulse); } }
void ThrowWaterBomb() { WaterBombScript waterBombScript = waterBomb.GetComponent <WaterBombScript> (); if (waterBombScript.numberOfBombs > 0) { waterBombScript.numberOfBombs--; // bomb is instantiated a bit forward from the water-bomb the player is holding GameObject bomb = Instantiate(Resources.Load("Prefabs/Water-Bomb"), waterBomb.transform.position + new Vector3(0f, 0, 1.5f), Quaternion.identity) as GameObject; // getting human's camera and adding force from it's looking point GameObject camera = GameObject.FindGameObjectWithTag("HumanCamera").gameObject; bomb.GetComponent <Rigidbody> ().AddForce(camera.transform.forward * throwForce, ForceMode.Impulse); } }
private float timeFillingUp = 0.0f; // used for refilling the weapons with water private void FillUpWater(GameObject weapon) { if (Input.GetKey(KeyCode.E)) { Debug.Log("Filling up current weapon with water"); // if the weapon is water gun if (weapon == waterGun) { WaterGunScript waterGunScript = waterGun.GetComponent <WaterGunScript> (); // assuming the water gun can have maximum of 30 ammo (10 in clip and 20 in reserve) int currentAmmo = waterGunScript.waterAmmoClip + waterGunScript.waterAmmoClip; if (currentAmmo < 30) { // filling up timeFillingUp += Time.deltaTime; // giving 1 ammo each second if (timeFillingUp > 1) { // firstly filling the clip if (waterGunScript.waterAmmoClip < 10) { waterGunScript.waterAmmoClip++; } else // then filling up the reserve ammo if (waterGunScript.waterAmmoAll < 20) { waterGunScript.waterAmmoAll++; } // resetting timeFillingUp = 0.0f; } } } if (weapon == waterBomb) { WaterBombScript waterBombScript = waterBomb.GetComponent <WaterBombScript> (); // assuming the player can only have maximum of 10 bombs if (waterBombScript.numberOfBombs < 10) { // filling up timeFillingUp += Time.deltaTime; // giving 1 bomb each 3 seconds if (timeFillingUp > 3) { waterBombScript.numberOfBombs++; // resetting timeFillingUp = 0.0f; } } } } }