/// <summary> /// Spawns a new target on the surface of the icosphere. /// </summary> private void SpawnTarget() { // Randomly select a new spawn point not equal to the previous point. _lastSpawnPointIndex = (Random.Range(1, _spawnPoints.Length / 2) + _lastSpawnPointIndex) % _spawnPoints.Length; // Create a new target object at that point, parented to the controller. GameObject target = Instantiate(_targetPrefab, transform); target.transform.position = _spawnPoints[_lastSpawnPointIndex] * 0.5f; // Subscribe to the new target's collection event. TargetController targetController = target.GetComponent <TargetController>(); targetController.Collected += OnCollected; // Pass on the reference rotation from calibration to the target controller. targetController.ReferenceRotation = _referenceRotation; }
/// <summary> /// Invoked when a target is collected. /// </summary> /// <param name="target">The target that was collected</param> private void OnCollected(TargetController target) { // Spawn a new target after a delay. Invoke("SpawnTarget", _spawnDelay); }