void ResetGame() { spawner.active = true; player = GameObjetcUtil.Instantiate(playerPrefab, new Vector3(0, (Screen.height / PixelPerfectCamera.pixelsToUnits) / 2, 0)); // create an instance of the player prfab + location of placement var playerDestrotScript = player.GetComponent <DestroyOffscreen>(); playerDestrotScript.DestroyCallback += OnPlayerKilled; // shorthand to link // tells the playerDestroyScript that when DestroyCallback gets called its actually going // to call OnPlayerKilled inside GameManager // connect delegate }
IEnumerator EnemyGenerator() // to return an interface of Ienumerator { yield return(new WaitForSeconds(delay)); // we want it to execute after the delay if (active) { var newTransform = transform; // position were we want to spawn, refernece to the existing trasform // of our game object GameObjetcUtil.Instantiate(prefabs[Random.Range(0, prefabs.Length)], newTransform.position); // Quaterion.identity: to set value of rotation to its defualt of zero ResetDelay(); // reset delay after a new obstacle is instantiated } StartCoroutine(EnemyGenerator()); // restart the coroutine so it continues to ru }