public void OnOutOfBounds() { offscreen = false; // reseting offscreen value GameObjetcUtil.Destroy(gameObject); if (DestroyCallback != null) { // meaning a method has been set to this property // we attempt to calll the method thast connected to it DestroyCallback(); } }
void OnTriggerEnter2D(Collider2D hitInfo) { // Debug.Log(hitInfo.name); DestroyOffscreen enemy = hitInfo.GetComponent <DestroyOffscreen>(); if (enemy != null) { enemy.TakeDamage(damage); } // Instantiate(impactEffect, transform.position, transform.rotation); GameObjetcUtil.Destroy(gameObject); }
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 }