protected GameControllerScript gameControllerScript; //подключаем скрипт гейм контроллера // Start is called before the first frame update void Start() { //Подключаем геймконтроллер скрипт gameControllerScript = GameObject.FindGameObjectWithTag("GameController"). GetComponent <GameControllerScript>(); ally = GetComponent <Rigidbody>(); ally.velocity = Vector3.forward * Random.Range(minSpeed, maxSpeed); if (gameControllerScript.GetIsStarted() == true) { // стрельба корабля InvokeRepeating("Shoot", firstShootDelay, Random.Range(minShootDelay, maxShootDelay)); //меняем направление движения InvokeRepeating("StrifeShip", 2.0f, Random.Range(strifeDecisionDelay, strifeDecisionDelay + 1.5f)); } }
// Update is called once per frame void Update() { // Если игра не началась, то ничего не происходит if (!gameControllerScript.GetIsStarted()) { return; } if (!IsBossEmitted) { //Запуск вражеских астероидов и истритбителей if (Time.time > nextLaunch) { int asteroidIndex = Random.Range(0, asteroids.Length); nextLaunch = Time.time + Random.Range(minDelay, maxDelay); float halfWidth = transform.localScale.x / 2; float positionX = Random.Range(-halfWidth, halfWidth); Vector3 newAsteroidPosition = new Vector3(positionX, transform.position.y, transform.position.z); Instantiate(asteroids[asteroidIndex], newAsteroidPosition, Quaternion.Euler(0, 180, 0)); } //запуск корабля подбитого пилота if (Time.time > nextDownedPilotLaunch) { nextDownedPilotLaunch = Time.time + Random.Range(8f, 14f); float halfWidth = transform.localScale.x / 2; float positionX = Random.Range(-halfWidth, halfWidth); Vector3 newdownedPilotPosition = new Vector3(positionX, transform.position.y, transform.position.z); Instantiate(downedPilot, newdownedPilotPosition, Quaternion.Euler(0, 180, 0)); Debug.Log("Downed Pilot Launch"); } } if (gameControllerScript.menu.activeInHierarchy == false) { // Периодический запуск щита if (Time.time > nextShieldLaunch) { nextShieldLaunch = Time.time + Random.Range(minShieldDelay, maxShieldDelay); float halfWidth = transform.localScale.x / 2; float positionX = Random.Range(-halfWidth, halfWidth); Vector3 newShieldPosition = new Vector3(positionX, transform.position.y, transform.position.z); Instantiate(shield, newShieldPosition, Quaternion.Euler(0, 180, 0)); } // Запуск нового блока снарядов if (Time.time > nextAmmoLaunch) { nextAmmoLaunch = Time.time + Random.Range(minAmmoLaunchDelay, maxAmmoLaunchDelay); float halfWidth = transform.localScale.x / 2; float positionX = Random.Range(-halfWidth, halfWidth); Vector3 newAmmoPosition = new Vector3(positionX, transform.position.y, transform.position.z); Instantiate(ammo, newAmmoPosition, Quaternion.Euler(0, 180, 0)); } // запуск нового комплекта бонусов Wing Support if (Time.time > nextWingSupportLaunch) { nextWingSupportLaunch = Time.time + Random.Range(minWingSupportDelay, maxWingSupportDelay); float halfWidth = transform.localScale.x / 2; float positionX = Random.Range(-halfWidth, halfWidth); Vector3 newWSPosition = new Vector3(positionX, transform.position.y, transform.position.z); Instantiate(wingSupport, newWSPosition, Quaternion.Euler(0, 180, 0)); } } // Увеличиваем уровень сложности (волну) if (scoreStep <= gameControllerScript.ShowScore()) { DelayCorrectionLow(); scoreStep += memoryScoreStep; Debug.Log("new wave " + scoreStep); gameControllerScript.IncreaseWave(); } // Восстанавливаем первичные показатели задержки при эмиссии объектов gameControllerScript.startButton.onClick.AddListener(delegate { minDelay = memoryStartMinDelay; maxDelay = memoryStartMaxDelay; minShieldDelay = memoryStartMinShieldDelay; maxShieldDelay = memoryStartMaxShieldDelay; }); // запускаем босса уровня if (gameControllerScript.GetIsBossReady() && !IsBossEmitted) { StartCoroutine(LaunchBoss()); IsBossEmitted = true; } // переключаем статус эмисии босса при нажатии кновки старт в положение выкл gameControllerScript.startButton.onClick.AddListener(delegate { IsBossEmitted = false; }); }
// Update is called once per frame void Update() { // 0. Пока игра не начата, ничего неделать (код ниже не исполняется) if (!gameControllerScript.GetIsStarted()) { return; } //1. Узнать куда хочет полететь игрок var moveHorizontal = Input.GetAxis("Horizontal"); // Куда хочет лететь игрок по горизонтали, -1...+1 var moveVertical = Input.GetAxis("Vertical"); //2. Полететь туда ship.velocity = new Vector3(moveHorizontal * strife, 0, moveVertical * speed); //3. Наклоняемся ship.rotation = Quaternion.Euler(moveVertical * tilt / 2, 0, -moveHorizontal * tilt); // костыль по оси Х(деление на 2), чтобы носом сильно не клевал, для красоты //4. Сковываем движения границами карты var xPosition = Mathf.Clamp(ship.position.x, xMin, xMax); var zPosition = Mathf.Clamp(ship.position.z, zMin, zMax); ship.position = new Vector3(xPosition, 0, zPosition); //5. Стреляем if (Input.GetButton("Fire1") && Time.time > nextShot && gameControllerScript.IsPaused == false) { if (ammoLargeLazer > 0) { if (lazerGun.activeInHierarchy == true) { Instantiate(lazerShot, lazerGun.transform.position, Quaternion.identity); } if (lazerGun2.activeInHierarchy == true) { Instantiate(lazerShot, lazerGun2.transform.position, Quaternion.identity); } if (lazerGun3.activeInHierarchy == true) { Instantiate(lazerShot, lazerGun3.transform.position, Quaternion.identity); } } ReduceAmmoLargeLaser(); //Instantiate(lazerShot, lazerGun2.transform.position, Quaternion.identity); //Instantiate(lazerShot, lazerGun3.transform.position, Quaternion.identity); nextShot = Time.time + lazerDelay; Debug.Log("Large laser ammo " + ammoLargeLazer); } if (ammoLargeLazer < 1) { StartCoroutine(ChargeLargeLaser()); } if (Input.GetButton("Fire2") && Time.time > nextShot) { if (ammoSmallLazer > 0) { Instantiate(rightShot, smallLazerRight.transform.position, Quaternion.Euler(0, 45, 0)); Instantiate(leftShot, smallLazerLeft.transform.position, Quaternion.Euler(0, -45, 0)); } ReduceAmmoSmallLaser(); nextShot = Time.time + smallLazerDelay; Debug.Log("Small laser ammo " + ammoSmallLazer); } if (ammoSmallLazer < 1) { StartCoroutine(ChargeSmallLaser()); } //восстановление боекомплекта при рестарте игры gameControllerScript.startButton.onClick.AddListener(delegate { ammoSmallLazer = maxAmmoSL; ammoLargeLazer = maxAmmoLR; gameControllerScript.largeLaserTxt.text = "Large Laser " + ammoLargeLazer; gameControllerScript.largeLaserTxt.color = Color.white; gameControllerScript.smallLaserTxt.text = "Small Laser " + ammoSmallLazer; gameControllerScript.smallLaserTxt.color = Color.white; foreach (GameObject lazer in gameControllerScript.largeLazers) { lazer.SetActive(true); } gameControllerScript.wpnStatusTxt.text = "All weapons in charge"; gameControllerScript.wpnStatusTxt.color = Color.white; }); }