private void SetPostion(EnemieComponent enemieComponent, bool spawnOnHorizontal, bool spawnOnNegativeXAxis, bool spawnOnNegativeYAxis) { float x, y; if (spawnOnHorizontal) { x = UnityEngine.Random.Range(0f, edgeOfRespawn.x / 2f); y = edgeOfRespawn.y / 2f; if (spawnOnNegativeYAxis) { y *= -1; } if (spawnOnNegativeXAxis) { x *= -1; } } else { x = edgeOfRespawn.x / 2f; y = UnityEngine.Random.Range(0f, edgeOfRespawn.y / 2f); if (spawnOnNegativeXAxis) { x *= -1; } if (spawnOnNegativeXAxis) { x *= -1; } } enemieComponent.transform.position = new Vector2(x, y); }
private void Start() { if (createParent) { var enemieParentGO = new GameObject("Enemies"); enemieParent = enemieParentGO.transform; } var numOfEnemieSettings = enemieData.Length; enemies = new List <EnemieComponent>(); enemiesPool = new Dictionary <EEnemieName, Queue <GameObject> >(); for (int i = 0; i < numOfEnemieSettings; i++) { var enemiesQueues = new Queue <GameObject>(); for (int j = 0; j < enemieData[i].maxNumOnScreen; j++) { GameObject newEnemieGO = Instantiate(enemieData[i].prefab) as GameObject; EnemieComponent enemie = newEnemieGO.GetComponent <EnemieComponent>(); enemies.Add(enemie); enemiesQueues.Enqueue(newEnemieGO); enemie.enemieName = enemieData[i].enemiesName; enemie.health = enemieData[i].health; enemie.damage = enemieData[i].damage; newEnemieGO.SetActive(false); if (createParent) { newEnemieGO.transform.parent = enemieParent; } } enemiesPool.Add(enemieData[i].enemiesName, enemiesQueues); } }
private void SetEnemiesProperties(EnemieComponent enemieComponent) { bool spawnOnHorizontal = UnityEngine.Random.Range(0f, 1f) < 0.5f; bool spawnOnNegativeXAxis = UnityEngine.Random.Range(0f, 1f) < 0.5f; bool spawnOnNegativeYAxis = UnityEngine.Random.Range(0f, 1f) < 0.5f; SetPostion(enemieComponent, spawnOnHorizontal, spawnOnNegativeXAxis, spawnOnNegativeYAxis); SetVelocity(enemieComponent, spawnOnHorizontal, spawnOnNegativeXAxis, spawnOnNegativeYAxis); }
private void DoContact(EnemieComponent enemie, int damage) { enemie.health -= damage; if (enemie.health <= 0) { Death(enemie); } enemie.wasContact = false; }
private void SetVelocity(EnemieComponent enemieComponent, bool spawnOnHorizontal, bool spawnOnNegativeXAxis, bool spawnOnNegativeYAxis) { Vector3 diagonalPos = new Vector3(-enemieComponent.transform.position.x, -enemieComponent.transform.position.y); var diagonal = diagonalPos - enemieComponent.transform.position; var perpendicularToDiagonal = Vector2.Perpendicular(diagonal).normalized *UnityEngine.Random.Range(1f, 4f); var velocity = (diagonal + new Vector3(perpendicularToDiagonal.x, perpendicularToDiagonal.y) * (UnityEngine.Random.Range(0f, 1f) < 0.5f ? -1 : 1)).normalized * enemieComponent.speed; enemieComponent.velocity = velocity; float rot_z = Mathf.Atan2(velocity.y, velocity.x) * Mathf.Rad2Deg; enemieComponent.transform.rotation = Quaternion.Euler(0f, 0f, rot_z - 90); }
private void Death(EnemieComponent enemie) { StateController.Instance.GetSystem <EnemiesSpawnSystem>().SetEneimeBack(enemie.enemieName, enemie.gameObject); }