IEnumerator SpawnEnemyFromRope() { yield return(new WaitForSeconds(1f)); SpawnRect spawnRect = playerEntity.spawnRect; spawnRect.rect.x += playerEntity.moveVelocity.x; spawnRect.rect.y += playerEntity.moveVelocity.z; Vector3 spawnPos = mapGen.GetSpawnPositionInRect(spawnRect) + Vector3.up; if (spawnPos != (Vector3.one * -1))//-1 Vector means the map wasn't able to find any available position, so just return and train again after 1 sec { Vector3 startSpawnPos = spawnPos + Vector3.up * 20f; Transform enemyT = PoolManager.instance.ReuseObject(enemy.gameObject, startSpawnPos, Quaternion.Euler(0f, Random.Range(0f, 360f), 0f)).transform; enemyT.GetComponent <Enemy>().SetCharacteristics(currentWave.moveSpeed, currentWave.hitsToKillPlayer, currentWave.enemyHealth); Transform rope = ((Rope)Instantiate(enemyT.GetComponent <Enemy>().rope, startSpawnPos, Quaternion.identity)).transform; PandaBehaviour panda = enemyT.GetComponent <PandaBehaviour>(); panda.enabled = false; float percent = 0f; float ropeVelocity = 1 / 0.3f; while (percent < 1) { percent += ropeVelocity * Time.deltaTime; rope.position = Vector3.Lerp(startSpawnPos, spawnPos, percent); yield return(null); } percent = 0; float climbDownVel = 1 / 1.5f; while (percent < 1) { percent += climbDownVel * Time.deltaTime; enemyT.position = Vector3.Lerp(startSpawnPos, spawnPos, percent); yield return(null); } Enemy spawnedEnemy = enemyT.GetComponent <Enemy>(); spawnedEnemy.OnDeath += OnEnemyDeath; enemyT.position = spawnPos; panda.enabled = true; spawnedEnemy.StartChase(); Destroy(rope.gameObject, 2); } }
public Vector3 GetSpawnPositionInRect(SpawnRect rect, float overlapBoxDimension = 2f) { Coord bottomLeft = GetTileFromPosition(rect.bottomLeft); Coord bottomRight = GetTileFromPosition(rect.bottomRight); Coord topLeft = GetTileFromPosition(rect.topLeft); SetSpawnPoints(bottomLeft.x, bottomRight.x, bottomLeft.y, topLeft.y, tileSize, overlapBoxDimension); if (shuffledSpawnPoints.Count <= 0) { return(Vector3.one * -1); } Coord spawnCoord = shuffledSpawnPoints.Dequeue(); shuffledSpawnPoints.Enqueue(spawnCoord); return(CoordToPosition(spawnCoord.x, spawnCoord.y)); }