IEnumerator eatGingerbread() { player.GetComponent <Controller> ().canMove = false; if (Random.Range(0, 2) == 0) { ammoComponent.ammo[0] += 10; } else if (Random.Range(0, 2) == 1) { ammoComponent.ammo[1] += 10; } if (Random.Range(0, 3) == 0) { ammoComponent.ammo[2]++; } for (int i = (int)eatTime * 10; i > 0; i -= 2) //Wait for eatTime and spawn breadcrubms meanwhile { Instantiate(breadcrumbs, mainCamera.transform.position, mainCamera.transform.localRotation); yield return(new WaitForSeconds(0.2f)); soundthing.playRandomClip(); if (player.GetComponent <PlayerHealth> ().health < 100) { player.GetComponent <PlayerHealth> ().health += (healthHealed * (0.2f / eatTime)); } } player.GetComponent <Controller> ().canMove = true; chomping = false; }
// Update is called once per frame void Update() { delay -= Time.deltaTime; ammoText0.text = "Flintlocks: " + ammoObject.ammo[0].ToString(); ammoText1.text = "Valters: " + ammoObject.ammo[1].ToString(); ammoText2.text = "Rocket Launchers: " + ammoObject.ammo[2].ToString(); if (Input.GetButton("Fire1")) { ammo[0] = ammoObject.ammo[0]; ammo[1] = ammoObject.ammo[1]; ammo[2] = ammoObject.ammo[2]; if (delay <= 0) { GameObject thrown; if (projectile.gameObject.name == "Flintlock") { if (ammo[0] > 0) { thrown = Instantiate(projectile); thrown.transform.position = Camera.main.transform.position; thrown.GetComponent <Rigidbody> ().velocity = (Camera.main.transform.forward * throwForce) + new Vector3(0, throwAngle, 0); thrown.GetComponent <Rigidbody> ().maxAngularVelocity = Mathf.Pow(10, 1000); thrown.GetComponent <Rigidbody> ().angularVelocity = angularVelocity; ammoObject.ammo[0] -= 1; ammoText0.text = "Flintlocks: " + ammoObject.ammo[0].ToString(); ammoText1.text = "Valters: " + ammoObject.ammo[1].ToString(); ammoText2.text = "Rocket Launchers: " + ammoObject.ammo[2].ToString(); soundthing.playRandomClip(); } } else if (projectile.gameObject.name == "Valter") { if (ammo[1] > 0) { thrown = Instantiate(projectile); thrown.transform.position = Camera.main.transform.position; thrown.GetComponent <Rigidbody> ().velocity = (Camera.main.transform.forward * throwForce) + new Vector3(0, throwAngle, 0); thrown.GetComponent <Rigidbody> ().maxAngularVelocity = Mathf.Pow(10, 1000); thrown.GetComponent <Rigidbody> ().angularVelocity = angularVelocity; ammoObject.ammo[1] -= 1; ammoText0.text = "Flintlocks: " + ammoObject.ammo[0].ToString(); ammoText1.text = "Valters: " + ammoObject.ammo[1].ToString(); ammoText2.text = "Rocket Launchers: " + ammoObject.ammo[2].ToString(); soundthing.playRandomClip(); } } else if (projectile.gameObject.name == "RocketLauncher") { if (ammo[2] > 0) { thrown = Instantiate(projectile); thrown.transform.position = Camera.main.transform.position; thrown.GetComponent <Rigidbody> ().velocity = (Camera.main.transform.forward * throwForce) + new Vector3(0, throwAngle, 0); thrown.GetComponent <Rigidbody> ().maxAngularVelocity = Mathf.Pow(10, 1000); thrown.GetComponent <Rigidbody> ().angularVelocity = angularVelocity; ammoObject.ammo[2] -= 1; ammoText0.text = "Flintlocks: " + ammoObject.ammo[0].ToString(); ammoText1.text = "Valters: " + ammoObject.ammo[1].ToString(); ammoText2.text = "Rocket Launchers: " + ammoObject.ammo[2].ToString(); soundthing.playRandomClip(); } } delay = startDelay; } ammoText0.text = "Flintlocks: " + ammoObject.ammo[0].ToString(); ammoText1.text = "Valters: " + ammoObject.ammo[1].ToString(); ammoText2.text = "Rocket Launchers: " + ammoObject.ammo[2].ToString(); } }