//set if its the player entering the portal public void OnTriggerEnter2D(Collider2D col) { if (col.name == "Player" && !isEndPoint) { //set inventory controller's current portal to this portal invc.currentportal = this; } if (col.tag == "draggable" && !isEndPoint) { RockMovement boxS = col.GetComponent <RockMovement>(); //set inventory controller's current portal to this portal controller.SendCrates(portalID, boxS.cratetype); Destroy(col.gameObject); } }
// Events. public void InitGameState() { gameOver = false; gameStarted = false; gameActive = false; totalCoins = 0; if (player != null) { ZombieController zc = player.GetComponent <ZombieController>(); if (zc != null) { zc.Init(); } } if (rock1 != null) { RockMovement rm = rock1.GetComponent <RockMovement>(); if (rm != null) { rm.Init(); } } if (rock2 != null) { RockMovement rm = rock2.GetComponent <RockMovement>(); if (rm != null) { rm.Init(); } } if (coin != null) { RockMovement rm = coin.GetComponent <RockMovement>(); if (rm != null) { rm.Init(); } } }
private IEnumerator SpawnRoutine() { WaitForSeconds PointThree = new WaitForSeconds(0.3f); WaitForSeconds ReloadTime = new WaitForSeconds(RELOAD_TIME); int enemyCount = 3; int RockCount = 5; while (true) { if (enemyCount > 0 && RockCount > 0) { int currentRand = Random.Range(0, 2); if (currentRand == 0) { RockMovement newAst = rockPool.GetFromPool(); newAst.transform.position = new Vector3(Random.Range(-5f, 5f), 0, 16); //위치 설정 RockCount--; yield return(PointThree); } else { EnemyController newEnemy = enemyPool.GetFromPool(); newEnemy.transform.position = new Vector3(Random.Range(-5f, 5f), 0, 16); enemyCount--; yield return(PointThree); } } else if (enemyCount > 0) { EnemyController newEnemy = enemyPool.GetFromPool(); newEnemy.transform.position = new Vector3(Random.Range(-5f, 5f), 0, 16); enemyCount--; RockCount = 5; yield return(PointThree); } else { RockMovement newAst = rockPool.GetFromPool(); newAst.transform.position = new Vector3(Random.Range(-5f, 5f), 0, 16); //위치 설정 RockCount--; enemyCount = 3; yield return(PointThree); } yield return(ReloadTime); } }
public RockMovement GetFromPool() { int idx = Random.Range(0, Prefab.Length); for (int i = 0; i < Pool[idx].Count; i++) { if (!Pool[idx][i].gameObject.activeInHierarchy) { Pool[idx][i].gameObject.SetActive(true); return(Pool[idx][i]); } } RockMovement temp = Instantiate(Prefab[idx]); temp.SetItemPool(itemPool); Pool[idx].Add(temp); return(temp); }
// Destroy everything that enters the trigger void OnTriggerEnter(Collider collider) { if (collider.gameObject.tag == "Coin") { RockMovement rm = collider.gameObject.GetComponent <RockMovement>(); if (rm != null) { rm.Respawn(); } else { Destroy(collider.gameObject); } if ((audioSource != null) && (coinSound != null)) { audioSource.PlayOneShot(coinSound); } GameManager.instance.CoinCollected(); } }