Created
July 17, 2017 16:19
-
-
Save JonathanYin/d73e87db5cfebfc9701b227e9750038c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using UnityEngine; | |
public class BombSpawner2 : MonoBehaviour | |
{ | |
// a public object array for which objects to spawn | |
public GameObject[] obj; | |
//min and max times for another spawn | |
public float spawnMin = 3f; | |
public float spawnMax = 2f; | |
private float wait = 0f; | |
public GameObject player1; | |
public GameObject player2; | |
void Start() | |
{ | |
//start spawn | |
Spawn(); | |
//StartCoroutine(ExecuteAfterTime(10)); | |
} | |
/*IEnumerator ExecuteAfterTime(float time) | |
{ | |
yield return new WaitForSeconds(time); | |
Instantiate(obj[Random.Range(0, obj.GetLength(0))], transform.position, Quaternion.identity); | |
//invoke spawn at random time interval between min and max | |
Invoke("Spawn", Random.Range(spawnMin, spawnMax)); | |
// Code to execute after the delay | |
}*/ | |
void Spawn() | |
{ | |
//get random number | |
float rand = Random.Range(0, 1000); | |
//if random number is greater than 700 make a bomb | |
if (rand > 700) | |
{ | |
if (player1 && player2) | |
{ | |
Debug.Log("player1 and player2 exist"); | |
Instantiate(obj[Random.Range(0, obj.GetLength(0))], transform.position, Quaternion.identity); | |
//invoke spawn at random time interval between min and max | |
} | |
} | |
Invoke("Spawn", Random.Range(spawnMin, spawnMax)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was a slight modification from my original BombSpawner script, and it is what I used for the "missile" projectiles that I had in my game. Since I realized that the game was slightly difficult with all its new features and obstacles, I changed up the script for one obstacle, making it so that once one player died, they would no longer spawn.