private void Update() { float inputHorizontal = Input.GetAxis("Horizontal"); float inputVertical = Input.GetAxis("Vertical"); if (inputHorizontal != 0.0f || inputVertical != 0.0f) { GlobalTimer.StartTimer(); } if (dying) { //transform.RotateAround(transform.position, Vector3.forward, dyingSeconds); render.transform.Rotate(new Vector3(0.0f, 0.0f, dyingSeconds * dyingSeconds)); shake.SetMagnitude(dyingSeconds * 0.01f); if (dyingSeconds > secondsBeforeDeathExplosion) { // Only proceed if the sprite is still visible. if (render.enabled) { // Create the death explosion! createBurst.SetSpread(360.0f); createBurst.SetCount(200); createBurst.Burst(Vector2.up); // Disable the sprite renderer. render.enabled = false; } } else { while (secondsSinceDeathPing > secondsBetweenDeathPings) { createBurst.Burst(Random.insideUnitCircle.normalized); secondsSinceDeathPing -= secondsBetweenDeathPings; } secondsSinceDeathPing += Time.deltaTime; if (secondsSinceDeathNoise > secondsBetweenDeathNoises) { PlaySoundDying(); secondsSinceDeathNoise -= secondsBetweenDeathNoises; } //secondsSinceDeathNoise += Time.deltaTime; secondsSinceDeathNoise += dyingSeconds; } if (dyingSeconds > secondsBeforeDeathRestart) { // Restart the scene. SceneUtil.ResetScene(); } dyingSeconds += Time.deltaTime; } else { //Vector2 move = new Vector2(inputHorizontal, inputVertical); Vector2 move = new Vector2(0.0f, inputVertical) * moveSpeed; float torque = -inputHorizontal * rotateSpeed; //Debug.Log(torque); rb.AddTorque(torque); rb.AddForce(transform.rotation * move); secondsSinceLastPing += Time.deltaTime; while (secondsSinceLastPing > secondsBetweenPings) { secondsSinceLastPing -= secondsBetweenPings; Burst(); } } if (Input.GetKeyDown(KeyCode.Escape)) { SceneUtil.ExitGame(); } }