private void CheckAmmo() { if (!fakeEndlessAmmo) { switch (weaponTyp) { case weaponTyps.rocket: if (rocketAmmo <= 0) weaponTyp = weaponTyps.mg; else rocketAmmo--; break; case weaponTyps.laser: if (laserAmmo <= 0) weaponTyp = weaponTyps.mg; else laserAmmo--; break; } } }
void Update() { Vector3 ubootposition = Camera.main.WorldToScreenPoint(transform.position); Vector2 aimPosition; fireTimer += Time.deltaTime; if (useGazeControl) { rawAimPosition = (gazeModel.posGazeLeft + gazeModel.posGazeRight) * 0.5f; rawAimPosition.y = (Screen.height - rawAimPosition.y); aimPosition = rawAimPosition; aimPosition.y = aimPosition.y - ubootposition.y; } else { aimPosition = Input.mousePosition; rawAimPosition = aimPosition; aimPosition.y = aimPosition.y - ubootposition.y; } crosshair.transform.position = Camera.main.ScreenToWorldPoint(rawAimPosition); crosshair.transform.position = new Vector3(crosshair.transform.position.x, crosshair.transform.position.y, 0); aimPosition.x = aimPosition.x - ubootposition.x; float angle; angle = Mathf.Atan2(aimPosition.y, aimPosition.x) * Mathf.Rad2Deg - 90; Vector3 rotationVector = new Vector3(0, 0, angle); transform.rotation = Quaternion.Euler(rotationVector); if (Input.GetButtonDown("Machine Gun")) { weaponTyp = weaponTyps.mg; fireTimer = weapon[(int)weaponTyp].fireRate; UpdateAmmo(); } else if (Input.GetButtonDown("Rocket") && rocketAmmo > 0 || Input.GetButtonDown("Rocket") && fakeEndlessAmmo) { weaponTyp = weaponTyps.rocket; fireTimer = weapon[(int)weaponTyp].fireRate; UpdateAmmo(); } else if (Input.GetButtonDown("Laser") && laserAmmo > 0 || Input.GetButtonDown("Laser") && fakeEndlessAmmo) { weaponTyp = weaponTyps.laser; fireTimer = weapon[(int)weaponTyp].fireRate; UpdateAmmo(); } if (fireTimer >= weapon[(int)weaponTyp].fireRate) { if (Input.GetButton("Fire1") && !gameOver.GetGameOver() && NetworkManagerScript.networkActive && networkView.isMine && !shootingBlocked || Input.GetButton("Fire1") && !gameOver.GetGameOver() && NetworkManagerScript.networkActive == false && !shootingBlocked) { CheckAmmo(); FireBullet(aimPosition); } } else { if (Input.GetButtonDown("Fire1") && !gameOver.GetGameOver() && !shootingBlocked) { CheckAmmo(); FireBullet(aimPosition); } } if (Input.GetButtonDown("Fire2")) { xRay.SetActive(true); } if (Input.GetButtonUp("Fire2")) { xRay.SetActive(false); GameObject[] eggs = GameObject.FindGameObjectsWithTag("Enemy"); foreach (GameObject egg in eggs) { if (egg.name == "EggEnemy(Clone)") { if (egg.GetComponent<EggEnemy>() != null) { egg.GetComponent<EggEnemy>().SetWhite(); } } } } }