// Update is called once per frame void Update() { SetRotation(); //Call the set rotation function each frame to ensure that the rotation setting operation always runs to completion timer += Time.deltaTime; //Increment the timer tracking the life of the laser shot if (timer > 0.6) //If the timer exceeds the lifespan of the laser animation, destroy this object { playerHealthControl.PlayerHit(1); if (playerHealthControl.currentPlayerHealth <= 0) { //playerHealthControl.DestroyPlayer(); playerHealthControl.StartCoroutine("DestroyPlayer"); } Destroy(gameObject); } }
private void GetExplosionNeighbours(Vector3Int origin, int explosionYield) { GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy"); Vector3Int playerPos = player.GetComponent <MovementController>().playerCellPosition; for (int x = -1 * explosionYield; x <= 1 * explosionYield; x++) { for (int y = -1 * explosionYield; y <= 1 * explosionYield; y++) { int modX = origin.x + x; int modY = origin.y + y; if (modX < mapManager.mapXMax && modX > mapManager.mapXMin && modY < mapManager.mapYMax && modY > mapManager.mapYMin) { if (mapManager.HexCellDistance(mapManager.evenq2cube(origin), mapManager.evenq2cube(new Vector3Int(modX, modY, 0))) <= 1 * explosionYield) { foreach (GameObject enemy in enemies) { Vector3Int enemyPos = gridLayout.WorldToCell(enemy.transform.position); if (enemyPos.x == modX && enemyPos.y == modY) { enemy.GetComponent <EnemyShipControl>().DestroySelf(true); } } if (playerPos.x == modX && playerPos.y == modY) { playerHealthControl.PlayerHit(1 * explosionYield); if (playerHealthControl.currentPlayerHealth <= 0) { //playerHealthControl.DestroyPlayer(); playerHealthControl.StartCoroutine("DestroyPlayer"); } } } } } } }