/// <summary> /// Manages collisions between projectile and other game objects /// </summary> /// <param name="other">Other.</param> void OnCollisionEnter2D(Collision2D other) { // Player loses and heart, projectile despawns, and player audio is triggered if (other.collider.CompareTag("Player")) { GameObject.FindGameObjectWithTag("playerdeath").GetComponent <AudioSource>().Play(); Destroy(gameObject); other.gameObject.GetComponent <Player> ().Die(); } else if (other.collider.CompareTag("shield")) { //Does nothing if it collides with shield } else if (other.collider.CompareTag("turret")) { //turret is destroyed, turret death audio is triggered, projectile despawns GameObject.FindGameObjectWithTag("enemydeath").GetComponent <AudioSource>().Play(); EnemyCount.KilledEnemy(); Destroy(gameObject); Destroy(other.collider.gameObject); } else { // if projectile hits any other object it is destroyed Destroy(gameObject); } }
public int EnCount = 0; //场景中的敌人数量 private void Awake() { _Instance = this; for (int i = 0; i < enemy.Length; i++) { enemyList.Add(enemy[i]); } EnCount = enemyList.Count; }
// Update is called once per frame void Update() { EnemyCount fixTracker = fixCount.GetComponent <EnemyCount>(); if (fixTracker.fixCount == fixTracker.fixRequired) { audioSource.Stop(); } }
public void Fix() { broken = false; rigidbody2D.simulated = false; animator.SetTrigger("Fixed"); EnemyCount count = fixTracker.gameObject.GetComponent <EnemyCount>(); count.fixCount += 1; smokeEffect.Stop(); }
public Quest(string name, int reward, EnemyCount count, EnemyDifficult difficult, Func <Ship> beginQuest) { Name = name; Reward = reward; Count = count; Difficult = difficult; Status = QuestStatus.NotStarted; BeginQuest = beginQuest; }
public void DisplayDialog() { EnemyCount count = fixTracker.gameObject.GetComponent <EnemyCount>(); if (count.fixCount == count.fixRequired) { timerDisplay = displayTime; winDialog.SetActive(true); canWait = true; } else { timerDisplay = displayTime; dialogBox.SetActive(true); } }
void OnCountChanged() { unitInfo.UnitCount.text = EnemyCount.ToString(); int totalCost = 0; for (int i = 0; i < EnemyCount; i++) { totalCost += selectedUnit.Cost; } if (GameController.instance.Money > totalCost + CalculateTotalCost()) { unitInfo.UnitTotalCost.color = new Color32(0, 236, 21, 255); } else { unitInfo.UnitTotalCost.color = new Color32(203, 7, 36, 255); } unitInfo.UnitTotalCost.text = totalCost.ToString() + "$"; }
public void PrepareWaves() { //gives the path string filePath = ProjectPaths.RESOURCES_MAP_SETTINGS + MapTypes.GetName(typeof(MapTypes), _mapType) + ".txt"; Debug.Log(filePath); //reads the lines in the path string[] rows = File.ReadAllLines(filePath); //iterates through all the lines int breakPoint = 0; for (int i = 0; i < rows.Length; i++) { //saves the point where the symbol is if (rows[i].Contains("#")) { breakPoint = i + 1; break; } } //create empty array with required size string[] waves = new string[rows.Length - breakPoint]; //copy this array to the other array Array.Copy(rows, breakPoint, waves, 0, rows.Length - breakPoint); //each wave in waves, turn into two ints //maybe use a string.somefunction() to separate the numbers? //add to List<Vector2Int>(); foreach (string wave in waves) { string[] enemyCounts = wave.Split(' '); //Debug.Log(enemyCounts[0]); //Debug.Log(enemyCounts[1]); EnemyCount enemyCount = new EnemyCount(Convert.ToInt32(enemyCounts[0]), Convert.ToInt32(enemyCounts[1])); WaveList.Add(enemyCount); } }
// Update is called once per frame void Update() { EnemyCount count = fixTracker.gameObject.GetComponent <EnemyCount>(); if (count.fixCount == count.fixRequired && canPlay == true) { PlaySound(victory); canPlay = false; } horizontal = Input.GetAxis("Horizontal"); vertical = Input.GetAxis("Vertical"); if (Input.GetKeyDown(KeyCode.X) || Input.GetButtonDown("Fire1")) { //RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.zero * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC")); RaycastHit2D hit = Physics2D.Raycast(rigidbody2d.position + Vector2.down * 0.2f, lookDirection, 1.5f, LayerMask.GetMask("NPC")); if (hit.collider != null) { Debug.Log("Raycast has hit the object " + hit.collider.gameObject); NonPlayableCharacter character = hit.collider.GetComponent <NonPlayableCharacter>(); if (character != null) { character.DisplayDialog(); } else { //ResourceCube(); ResourceCube cube = hit.collider.GetComponent <ResourceCube>(); cube.GetResources(); Destroy(hit.collider.gameObject); } } } //if(Input.GetKeyDown(KeyCode.C) && ammo > 0) //{ // Launch(); // PlaySound(throwSound); //} if (Input.GetButtonDown("Fire3") && ammo > 0) { Launch(); PlaySound(throwSound); } Vector2 move = new Vector2(horizontal, vertical); if (!Mathf.Approximately(move.x, 0.0f) || !Mathf.Approximately(move.y, 0.0f)) { lookDirection.Set(move.x, move.y); lookDirection.Normalize(); } animator.SetFloat("Look X", lookDirection.x); animator.SetFloat("Look Y", lookDirection.y); animator.SetFloat("Speed", move.magnitude); if (isInvincible) { invincibleTimer -= Time.deltaTime; if (invincibleTimer < 0) { isInvincible = false; } } if (currentHealth <= 0) { SceneManager.LoadScene(currentScene.name); } }