// Reactivating the stage after it has been cleared. public void Reactivate() { // Resetting some values. moveCooldown = staticMoveCooldown; moveMultiplier = 1; randomShootingLimit = 0.1f; int x = 0; for (int i = -24; i <= 24; i += 2) { for (int y = 5; y <= 17; y += 3) { // Instantiating objects takes a bit more resources so we can just disable the ships instead. Vector2 shipPos = new Vector2(i, y); enemyShips[x].transform.position = shipPos; enemyShips[x].SetActive(true); enemyShips[x].GetComponent <BoxCollider2D>().enabled = true; ++x; } } shipsLeft = x; // Making sure that they are moving into the right direction and that the sprite that they begin with is correct. foreach (GameObject enemyShip in enemyShips) { EnemyShipScript ess = enemyShip.GetComponent <EnemyShipScript>(); ess.shouldMove = true; ess.moveDown = false; ess.ResetSprite(); } checkShipsBool = true; ApproachScript.instance.enabled = true; }
void UpdateIndicator(GameObject ship, int index) { RaycastHit hit; var indicator = _indicatorList[index]; var rayCastDirUp = _player.transform.up.normalized; //_radarPlane.mesh.normals[0]; //Debug.DrawRay(ship.transform.position, rayCastDirUp * 50, Color.red, 1f); if (Physics.Raycast(ship.transform.position, rayCastDirUp, out hit, 500f, LayerMask.GetMask("Radar"))){ //Debug.Log("It's a hit!"); var dir = (hit.point - _player.transform.position).normalized; //Debug.DrawRay(ship.transform.position, dir * 50, Color.green, 1f); indicator.transform.rotation = Quaternion.LookRotation(dir); indicator.gameObject.SetActive(true); } else { indicator.gameObject.SetActive(false); } if (!ship.GetComponent<EnemyShipScript>().hasLanded){ var pointer = indicator.transform.GetChild(0); _currentShipScript = ship.GetComponent<EnemyShipScript>(); var startLandingHeight = _currentShipScript.GetStartLandingHeight(); var currDistFromPlanet = _currentShipScript.GetDistanceFromPlanetSurface(); //pointer.transform.localScale = new Vector3(pointer.transform.localScale.x, pointer.transform.localScale.y, ship.GetComponent<EnemyShipScript>().GetDistanceFromPlanetSurface() / _enemySpawnDistance); if(currDistFromPlanet > startLandingHeight) pointer.transform.localScale = new Vector3(pointer.transform.localScale.x, pointer.transform.localScale.y, 1); else pointer.transform.localScale = new Vector3(pointer.transform.localScale.x, pointer.transform.localScale.y, currDistFromPlanet/startLandingHeight); } else { RemoveShipToTrack(ship); } }
// Start is called before the first frame update void Start() { ess = GameObject.Find("EnemyShipGenerator").GetComponent <EnemyShipScript>(); fss = GameObject.Find("FriendlyShipGenerator").GetComponent <FriendlyShipScript>(); lighthouse = GameObject.Find("Headless_light_house"); friendlyGenerator = GameObject.Find("FriendlyShipGenerator"); offset = new Vector3(2, 0, 2); //cannonball = GameObject.FindGameObjectWithTag("CannonballAttack"); //cannonballTransform = cannonball.transform; originalRotation = transform.rotation; }
// Every 10 seconds, select a random ship that would be special for 7 seconds. If player hits the ship while it's in that state, player gains rapid fire. private void SpecialShip() { specialShipTimer += Time.deltaTime; if (specialShipTimer >= 10f) { specialShipTimer = 0f; bool exitCondition = false; List <GameObject> tempShipList = enemyShips; GameObject ship; int n = 0; // Taking care of edge cases (no ships remaining, ship count is 0, only one ship remaining but it's in a dying state). for (int i = 0; i < tempShipList.Count; ++i) { if (i == tempShipList.Count - 1) { if (!tempShipList[i].activeSelf || tempShipList[i].GetComponent <EnemyShipScript>().deathBool) { exitCondition = true; } } if (tempShipList[i].activeSelf && !tempShipList[i].GetComponent <EnemyShipScript>().deathBool) { break; } } if (tempShipList.Count == 0) { exitCondition = true; } // Since the ship count is not that big, it takes about ~35 iterations to get to the ship when there is only one left. // Considering this fires only each 10 seconds - not a big deal. while (!exitCondition) { ++n; ship = tempShipList[Random.Range(0, tempShipList.Count)]; EnemyShipScript shipScript = ship.GetComponent <EnemyShipScript>(); if (ship.activeSelf && !shipScript.deathBool && !shipScript.isSpecial) { FlashingScript flashingScript = ship.GetComponent <FlashingScript>(); flashingScript.colorSaturation = 0.3f; flashingScript.colorBool = true; shipScript.isSpecial = true; exitCondition = true; } } } }
private void OnTriggerEnter2D(Collider2D col) { // Colliding with enemy ship. if (col.gameObject.name.StartsWith("EnemyShip") && !col.GetComponent <EnemyShipScript>().deathBool) { col.GetComponent <BoxCollider2D>().enabled = false; // Increase the score. EnemyShipScript enemyShipScript = col.GetComponent <EnemyShipScript>(); ManagerScript.instance.score += enemyShipScript.scoreToGive; GameObject.Find("ScoreText").GetComponent <TMP_Text>().text = "SCORE: " + ManagerScript.instance.score; // Initiate enemy ship death. --ManagerScript.instance.shipsLeft; enemyShipScript.isDying = true; enemyShipScript.deathBool = true; enemyShipScript.shouldMove = false; col.GetComponent <SpriteRenderer>().sprite = deathSprite; // Game, along with the approach sounds speed up as we kill enemy ships. ManagerScript.instance.moveCooldown -= 0.0075f; if (ManagerScript.instance.moveCooldown <= 0.03f) { ManagerScript.instance.moveCooldown = 0.03f; } ManagerScript.instance.randomShootingLimit += 0.02f; ApproachScript.instance.frequency = ManagerScript.instance.moveCooldown; // Rapid fire. If already on rapid fire - refresh. if (enemyShipScript.isSpecial) { if (!PlayerScript.instance.rapidFire) { enemyShipScript.specialTimer = 8f; PlayerScript.instance.rapidFire = true; ManagerScript.instance.tilemapFlashingScript.colorSaturation = 0.3f; ManagerScript.instance.tilemapFlashingScript.colorBool = true; } else { PlayerScript.instance.rapidFireTimer = 0f; } } // If there are no more enemy ships, initiate stage clear text. if (ManagerScript.instance.shipsLeft == 0) { Instantiate(stageClearTextPrefab, Vector3.zero, Quaternion.identity, GameObject.Find("WorldSpaceCanvas").transform); ManagerScript.instance.checkShipsBool = false; ApproachScript.instance.frequency = 1f; ApproachScript.instance.enabled = false; } } else if (col.gameObject.name.StartsWith("Mothership") && !col.GetComponent <MothershipScript>().isDead) { col.GetComponent <MothershipScript>().isDead = true; // Missile collides with the mothership - adding randomized score as well as flashing it on the screen where the mothership was destroyed. int ran = Random.Range(5, 10); int scoreAddition = ran * 100; ManagerScript.instance.score += scoreAddition; GameObject.Find("ScoreText").GetComponent <TMP_Text>().text = "SCORE: " + ManagerScript.instance.score; TMP_Text text = Instantiate(mothershipScoreTextPrefab, col.transform.position, Quaternion.identity, GameObject.Find("WorldSpaceCanvas").transform); text.text = scoreAddition.ToString(); Destroy(col.gameObject); // When hitting the mothership, player gets increased power. if (PlayerScript.instance.missileUpgrade < 4) { Instantiate(ManagerScript.instance.missilePowerIncreasedText, Vector2.zero, Quaternion.identity, GameObject.Find("WorldSpaceCanvas").transform); ++PlayerScript.instance.missileUpgrade; } } --PlayerScript.instance.missileCount; // Putting the missile back in the pool. transform.gameObject.SetActive(false); transform.position = PoolingScript.instance.missilePoolPosition; }
public void HurtEnemyMethod(EnemyShipScript objectToHurt, float damageToTake) { objectToHurt.enemyHealth -= damageToTake; }
// Start is called before the first frame update void Start() { theEnemyShipScript = FindObjectOfType <EnemyShipScript>(); theLevelManager = FindObjectOfType <LevelManager>(); }