private void InstantiateEnemy() { var minPos = CameraUtils.GetMousePosition2D(new Vector2(0, 0)); var maxPos = CameraUtils.GetMousePosition2D( new Vector2(Screen.width, Screen.height) ); var posY = Random.Range(minPos.y, maxPos.y); var spawnPosition = new Vector3(maxPos.x, posY); var obj = enemyPooling.GetAvailableObject(); if (!obj.IsPresent) { return; } var enemyObj = obj.Get(); enemyObj.transform.position = spawnPosition; enemyObj.GetComponent <HealthSystem>().HealFull(); var movementIdx = Random.Range(0, enemyMovementTypes.Count); if (movementIdx != 0) { var mov = enemyMovementTypes[movementIdx]; enemyMovementPooling.GetAvailableObject(mov) .Some(obj => { obj.transform.position = spawnPosition; obj.Activate <SplineMonoBehaviour>( sObj => enemyObj .GetComponent <SplineFollower>() .Setup( sObj, mov == "circle" ? SplineFollowBehaviour.loop : SplineFollowBehaviour.backAndForth ) ); }); } enemyObj.Activate(); }