public static CollectibleControl Create(CollectibleData data, Vector3 initialPos) { GameObject collectible = Instantiate(Resources.Load("Prefabs/" + data.name)) as GameObject; collectible.transform.position = initialPos; CollectibleControl cc = collectible.GetComponent <CollectibleControl>(); cc.speed = data.speed; cc.value = data.value; cc.stamina = data.stamina; cc.name = data.name; return(cc); }
IEnumerator SpawnWaves() { while (spawning) { int randX = Random.Range(0, initialX.Length); Vector3 randPos = new Vector3(initialX[randX], initialY, -0.1f); //Since river means instant death, make sure there is an interval between two rivers int riverCount = 0; int currentLevel = GameManager.GetLevel() + 1; if (currentLevel > EnemyTypes.Count) { currentLevel = EnemyTypes.Count; } //Spawn everything for debugging //currentLevel = EnemyTypes.Count; int typeRand = Random.Range(0, 100); if (typeRand < 60) { int randType = Random.Range(0, currentLevel); if (buffer[EnemyTypes[randType].name].Count > 0) { GameObject g = buffer[EnemyTypes[randType].name].Pop(); g.transform.position = randPos; g.SetActive(true); } else { EnemyControl.Create(EnemyTypes[randType], randPos); } riverCount--; } else if (typeRand < 98) { int randType = Random.Range(0, CollectibleTypes.Count); if (buffer[CollectibleTypes[randType].name].Count > 0) { GameObject c = buffer[CollectibleTypes[randType].name].Pop(); c.transform.position = randPos; c.SetActive(true); } else { CollectibleControl.Create(CollectibleTypes[randType], randPos); } riverCount--; } else { if (riverCount == 0 && currentLevel > 3) { riverCount = riverInterval; int randType = Random.Range(0, RiverTypes.Count); if (buffer[RiverTypes[randType].name].Count > 0) { GameObject r = buffer[RiverTypes[randType].name].Pop(); r.transform.position = randPos; r.SetActive(true); } else { RiverControl.Create(RiverTypes[randType], randPos); } } } yield return(new WaitForSeconds(spawnInterval)); } }
void OnCollisionEnter(Collision collision) { if (!collisionEnabled) { return; } string otherTag = collision.gameObject.tag; switch (otherTag) { case "Enemy": EnemyControl ec = collision.gameObject.GetComponent <EnemyControl>(); if (ec) { if (ec.gameObject.name == "SpaceInvader") { SpaceInvaderControl sc = (SpaceInvaderControl)ec; sc.Action(gm); } else if (ec.gameObject.name == "Goomba") { GoombaControl gc = (GoombaControl)ec; gc.Action(gm); } else if (ec.gameObject.name == "Bomb") { BombControl bc = (BombControl)ec; bc.Action(gm); gm.AddStamina(-100); gameObject.SetActive(false); GameObject explosion = Instantiate(Resources.Load("Prefabs/Explosion")) as GameObject; explosion.transform.position = gameObject.transform.position; } else if (ec.gameObject.name == "Ghost") { GhostControl gc = (GhostControl)ec; gc.Action(gm); } else { //se.PlaySE("cry"); //ec.Action(gm); } } break; case "River": if (!isJumping) { //GetComponent<Renderer>().isVisible = false; RiverControl rc = collision.gameObject.GetComponent <RiverControl>(); if (rc) { rc.Action(gm); } gameObject.SetActive(false); GameObject splash = Instantiate(Resources.Load("Prefabs/Splash")) as GameObject; splash.transform.position = gameObject.transform.position; } break; case "Collectible": CollectibleControl cc = collision.gameObject.GetComponent <CollectibleControl>(); if (cc.gameObject.name == "Cherry") { gm.MakeGhostsVulnerable(); //CherryControl cherry = (CherryControl)cc; //cherry.Action(gm); cc.Action(gm); } else { cc.Action(gm); } break; } }