private IEnumerator Start() { for (int i = 0; i < _spawnCount; i++) { GameObject plane = planeFactory.CreateRandomPlane(Vector3.zero, Quaternion.identity); IPathable pathable = plane.GetComponent <IPathable>(); if (!pathable.IsNull() && nodes.Count > 0) { pathable.StartPath(nodes[0].transform.position); for (int x = 1; x < nodes.Count; x++) { pathable.AddPathPosition(nodes[x].transform.position); } pathable.EndPath(); } yield return(new WaitForSeconds(1f)); } }
private void Spawn() { float angle = ((Mathf.PI * 2) * Random.value); float sin = Mathf.Sin(angle); float cos = Mathf.Cos(angle); // Pick a spawn position Vector3 spawnPosition = _root.position; spawnPosition.x += _radius * sin; spawnPosition.z += _radius * cos; GameObject go = _factory.CreateRandomPlane(spawnPosition, Quaternion.identity); go.transform.SetParent(_root); // Grab our directable component IDirectable iDirectable = go.GetComponent <IDirectable>(); // Set our primary travel position Vector3 primaryTravelPosition = _root.position; primaryTravelPosition.x += (_radius - _primaryTargetRadiusOffset) * sin; primaryTravelPosition.z += (_radius - _primaryTargetRadiusOffset) * cos; primaryTravelPosition.y += _primaryTargetHeightOffset; // Secondary Point angle = ((Mathf.PI * 2) * Random.value); Vector3 holdingPosition = _playerTransform.position; float hpRadius = Random.value * _holdingPositionRadius * _playerTransform.scale; holdingPosition.x += sin * hpRadius; holdingPosition.z += cos * hpRadius; Flightpath flightPath = new Flightpath(primaryTravelPosition); flightPath.drawPath = false; flightPath.AddPosition(holdingPosition); flightPath.Finialized(); iDirectable.AssignPath(flightPath, true); }