// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { AutoFade.LoadLevel("Level Select", Color.white); } /*if(Input.GetKeyDown(KeyCode.P)) { * PlayerDie(); * }*/ if (isDead || Camera.main == null) { return; } if (optionalDangerHeightMeasure) { int diff = (int)(transform.position.y - optionalDangerHeightMeasure.transform.position.y); if (diff > 0) { optionalDangerHeightReadout.text = dangerBaseText; } else { optionalDangerHeightReadout.text = "" + (-diff) + "m below detection"; } } float wasThrottle = throttle; /*if(missionTarget == null) { * transform.rotation = * Quaternion.Slerp(transform.rotation, * Quaternion.LookRotation(Vector3.up), Time.deltaTime * 3.0f); * throttle = 1.0f; * isHairpin180 = false; * } else {*/ if (Input.GetKeyDown(KeyCode.Alpha1)) { throttle = 0.0f; } else if (Input.GetKeyDown(KeyCode.Alpha2)) { throttle = 0.1f; } else if (Input.GetKeyDown(KeyCode.Alpha3)) { throttle = 0.2f; } else if (Input.GetKeyDown(KeyCode.Alpha4)) { throttle = 0.3f; } else if (Input.GetKeyDown(KeyCode.Alpha5)) { throttle = 0.4f; } else if (Input.GetKeyDown(KeyCode.Alpha6)) { throttle = 0.5f; } else if (Input.GetKeyDown(KeyCode.Alpha7)) { throttle = 0.6f; } else if (Input.GetKeyDown(KeyCode.Alpha8)) { throttle = 0.7f; } else if (Input.GetKeyDown(KeyCode.Alpha9)) { throttle = 0.8f; } else if (Input.GetKeyDown(KeyCode.Alpha0)) { throttle = 1.0f; } //} if (throttle > wasThrottle) { SoundCenter.instance.PlayClipOn( SoundCenter.instance.throttleUp, transform.position, 1.0f, transform); } else if (throttle < wasThrottle) { SoundCenter.instance.PlayClipOn( SoundCenter.instance.throttleDown, transform.position, 1.0f, transform); } asymThrot = (1.0f - throttleSmooth); asymThrot *= asymThrot; asymThrot = 1.0f - asymThrot; engineVolume.volume = 0.1f + 0.7f * asymThrot; if (maxThrottle) { asymThrot *= 4.0f; } float newFOV = 55.0f + asymThrot * 10.0f; float kSpring = 0.95f; stretchFOV.fieldOfView = kSpring * stretchFOV.fieldOfView + (1.0f - kSpring) * newFOV; transform.position += asymThrot * transform.forward * Time.deltaTime * maxSpeed; float dodgeInput = Input.GetAxisRaw("Roll"); if (activelyStrafing) { if (dodgeInput == 0.0f) { activelyStrafing = false; } } else { if (dodgeInput < -0.1f) { strafeAxis = transform.right; activelyStrafing = true; SoundCenter.instance.PlayClipOn( SoundCenter.instance.playerDodge, transform.position, 1.0f, transform); } else if (dodgeInput > 0.1f) { strafeAxis = -transform.right; activelyStrafing = true; SoundCenter.instance.PlayClipOn( SoundCenter.instance.playerDodge, transform.position, 1.0f, transform); } } if (rocketReloadTimeLeft > 0.0f) { rocketReloadTimeLeft -= Time.deltaTime; if (rocketReloadTimeLeft <= 0.0f || GameStateStaticProgress.cheatsOn) { if (rocketsLoaded < 4) { if (rocketsLoaded == 0) { rocketHUD.gameObject.SetActive(true); } rocketHUD.sprite = rocketGraphics[rocketsLoaded]; rocketsLoaded++; rocketReloadTimeLeft = rocketReloadTime; } } } if (Input.GetKeyDown(KeyCode.Return)) { if (rocketSalvo == 0 && rocketsLoaded > 0) { if (GameStateStaticProgress.cheatsOn == false) { rocketSalvo = rocketsLoaded; rocketReloadTimeLeft = rocketReloadTime; rocketsLoaded = 0; rocketHUD.gameObject.SetActive(false); } else { rocketSalvo = rocketsLoaded; } } else { SoundCenter.instance.PlayClipOn( SoundCenter.instance.laserFire, transform.position, 1.0f, transform); } } if (Input.GetKeyDown(KeyCode.X) && isHairpin180 == false /*&& missionTarget != null*/) { SoundCenter.instance.PlayClipOn( SoundCenter.instance.playerDodge, transform.position, 1.0f, transform); isHairpin180 = true; hairpinSpinAmt = 0.0f; spin180From = transform.rotation; spin180Goal = transform.rotation * Quaternion.AngleAxis(180.0f, Vector3.right); } /*if(missionTarget == null) { * // on autopilot, ignore inputs * } else*/if (isHairpin180 == false) { isTurningDampenSpeed = (Mathf.Abs(Input.GetAxis("Vertical")) > 0.2f || Mathf.Abs(Input.GetAxis("Horizontal")) > 0.2f); transform.Rotate( Input.GetAxis("Vertical") * Time.deltaTime * pitchSpeed, Input.GetAxis("Horizontal") * Time.deltaTime * yawSpeed, (GameStateStaticProgress.uprightDodge ? 0.0f : Input.GetAxis("Roll") * Time.deltaTime * rollSpeed) ); transform.position += strafeAxis * Time.deltaTime * dodgeSpeed; } else { bool wasBelow = (hairpinSpinAmt < 0.5f); hairpinSpinAmt += Time.deltaTime * 0.7f; isTurningDampenSpeed = true; if (hairpinSpinAmt < 0.5f) { float halfTurn = hairpinSpinAmt * 2.0f; transform.rotation = Quaternion.Lerp(spin180From, spin180Goal, halfTurn); } else { float lastTurn = hairpinSpinAmt * 2.0f - 1.0f; if (wasBelow) { SoundCenter.instance.PlayClipOn( SoundCenter.instance.throttleDown, transform.position, 1.0f, transform); spin180From = transform.rotation; spin180Goal = transform.rotation * Quaternion.AngleAxis(180.0f, Vector3.forward); } transform.rotation = Quaternion.Lerp(spin180From, spin180Goal, lastTurn); } if (hairpinSpinAmt > 1.0f) { SoundCenter.instance.PlayClipOn( SoundCenter.instance.throttleUp, transform.position, 1.0f, transform); isHairpin180 = false; } } updateThrottleReadout(); updateHealthReadout(); updateTargetReadout(); if (gunCooldownTimeLeft >= 0.0f) { gunCooldownTimeLeft -= Time.deltaTime; } if (reloadTime >= 0.0f) { reloadTime -= Time.deltaTime; } else if (Input.GetKey(KeyCode.Space) && gunCooldownTimeLeft <= 0.0f) { gunHeat += timeBetweenShots * 0.5f; if (gunHeat > 1.0f) { if (GameStateStaticProgress.cheatsOn) { gunHeat = 1.0f; } else { gunCooldownTimeLeft = cooldownTimeNeeded; SoundCenter.instance.PlayClipOn( SoundCenter.instance.throttleDown, transform.position, 1.0f, transform); } } mFlash.Strobe(); SoundCenter.instance.PlayClipOn( SoundCenter.instance.playerMG2, transform.position, Random.Range(0.2f, 0.4f), transform); Ray playerGun = new Ray(transform.position, transform.forward); float missBy = 0.75f; Quaternion missQuat = Quaternion.AngleAxis(Random.Range(-missBy, missBy), Camera.main.transform.up); missQuat = missQuat * Quaternion.AngleAxis(Random.Range(-missBy, missBy), Camera.main.transform.right); playerGun.direction = missQuat * playerGun.direction; RaycastHit rhInfo; int layerMask = ~(1 << 12); if (Physics.Raycast(playerGun, out rhInfo, 4000.0f, layerMask)) { Vector3 towardPlayer = rhInfo.point - transform.position; GameObject newGo = (GameObject)GameObject.Instantiate( spawnUponShotHit, rhInfo.point - towardPlayer.normalized * 2.0f, Quaternion.identity ); newGo.transform.parent = rhInfo.collider.transform; Shootable thingShot = rhInfo.collider.GetComponent <Shootable>(); SoundCenter.instance.PlayClipOn( SoundCenter.instance.playerMG1, transform.position, Random.Range(0.3f, 0.4f), transform); if (thingShot) { thingShot.DamageThis(); } // Destroy( rhInfo.collider.gameObject ); } reloadTime = timeBetweenShots; } else if (gunHeat > 0.0f) { gunHeat -= Time.deltaTime; if (gunHeat < 0.0f) { gunHeat = 0.0f; } } }