// Update is called once per frame and is frame dependent void FixedUpdate() { Vector2 inputVector = Vector2.zero; switch (aiMode) { case AIMode.followPlayer: FollowPlayer(); break; case AIMode.followWaypoints: FollowWaypoints(); break; } inputVector.x = TurnTowardTarget(); inputVector.y = 1.0f - inputVector.x / 0.9f; //Make the ship accelerate less while turning AimAtPlayer(); FireAtPlayer(); //Send the input to the car controller. shipMovementHandler.SetInput(inputVector); }
// Update is called once per frame void Update() { Vector2 inputVector = Vector2.zero; inputVector.y = Input.GetAxis("Vertical"); inputVector.y = Mathf.Clamp01(inputVector.y); //Sorry you cannot go forward without fuel. if (shipFuelHandler.IsOutOfFuel()) { inputVector.y = 0; } inputVector.x = Input.GetAxis("Horizontal"); isFiring = Input.GetButton("Fire1"); if (isFiring) { heatLevel += Time.deltaTime * 0.3f; } else { heatLevel -= Time.deltaTime * 0.5f; } heatLevel = Mathf.Clamp01(heatLevel); shipMovementHandler.SetInput(inputVector); Vector3 mousePosition = Input.mousePosition; mousePosition.z = Camera.main.transform.position.y; for (int i = 0; i < weaponHandlers.Length; i++) { Vector3 mouseWorldPosition = Camera.main.ScreenToWorldPoint(new Vector3(mousePosition.x, mousePosition.y, transform.position.z - 10)); Vector3 aimVector = mouseWorldPosition - weaponHandlers[i].transform.position; aimVector.Normalize(); weaponHandlers[i].SetAimVector(aimVector); } if (IsFiring()) { laserAudioSource.volume = Mathf.Lerp(laserAudioSource.volume, 1.0f, Time.deltaTime * 15); } else { laserAudioSource.volume = Mathf.Lerp(laserAudioSource.volume, 0, Time.deltaTime * 10); } }