// Update is called once per frame void Update() { //If list of sounds is empty, populate it if (powerBarAudioClips.Count == 0) { loadSound(); } //if there is no ball yet if (ballFound == false) { if (jackThrown == false) { ball = GameObject.FindGameObjectWithTag("Jack"); rb = ball.GetComponent <Rigidbody>(); } //Update powerbar powerBar.updatePowerBar(); } //if ball isn't thrown if (ballThrown == false) { //update balls position until thrown ball.transform.position = transform.position + (transform.forward * 2); ball.transform.rotation = transform.rotation; //If game is unpaused if (cont.GetPlayRound()) { //Increase x - power by 1 if (Input.GetKeyDown("up") || Input.GetButtonDown("B") || Input.GetAxis("MouseScrollWheel") > 0) { if (power < 10) { //Convert power from float to int float current = power * 2; int currentB = (int)current; //Set clip based on power audioSource.clip = powerBarAudioClips[currentB]; //Play audioSource.Play(); //Increase power power += 1.0f; //Update aim assist aimAssistScript.CalculateAimIncreased(); //reduce player turning speed based on power player.GetComponent <PlayerControls>().powerRotModifier -= 0.1f; } //Update powerbar powerBar.updatePowerBar(); } //Decrease x - power by 1 if (Input.GetKeyDown("down") || Input.GetButtonDown("A") || Input.GetAxis("MouseScrollWheel") < 0) { if (power > 0) { //Decrease power power -= 1.0f; //Convert power from float to int float current = power * 2; int currentB = (int)current; //Set clip based on power audioSource.clip = powerBarAudioClips[currentB]; //Play audioSource.Play(); //Update aim assist aimAssistScript.CalculateAimReduced(); //increase player turning speed based on power player.GetComponent <PlayerControls>().powerRotModifier += 0.1f; } //Update powerbar powerBar.updatePowerBar(); } //Apply force on release if (Input.GetKeyDown("space") || Input.GetButtonDown("X") || Input.GetButtonDown("LeftMouseButton")) { //rb.useGravity = true; //Apply force to ball //Z - Force based on rotation //Steve - added more force due to mass changes for phsyics //rb.AddForce(power*4, 0, -power_z*4, ForceMode.Impulse); rb.AddForce(transform.forward * power * 400); rb.useGravity = true; if (ball.tag == "Jack") { jackThrown = true; } else { cont.amountOfBalls++; } //ball is thrown and can't be touched ballThrown = true; shotTime = Time.time; audioSource.clip = ballThrowSound; audioSource.Play(); //Update scoreboard scoreBoardScript.UpdateScoreboard(); //reset player power modifier player.GetComponent <PlayerControls>().powerRotModifier = 1.1f; } } } }