public void LaunchMinion(Vector3 toWhere) { if (minionList.Count <= 0 || rebuildCoroutine != null || toWhere == Vector3.zero) { return; } foreach (Transform child in minionList) { //Launch the minion child.GetComponent <Rigidbody2D>().velocity = (toWhere - child.position).normalized * minionSpeed; OrbitAroundObject orbitScript = child.GetComponent <OrbitAroundObject>(); if (orbitScript != null) { orbitScript.enabled = false; //Stop it from orbiting around } //Put it directly into object master's list child.parent = null; objectMasterScript.AddChild(child); } minionList.Clear(); }
public virtual bool SpawnEnemy(int indx) { int chance = Random.Range(0, 101); if (chance < enemySpawnChance[indx]) { //Spawn the enemy Transform newEnemy = Instantiate(enemyList[indx].myObject, objectMasterScript.transform); //Put the enemy into the right place Vector3 newPos = new Vector3(Random.Range(xScreen.x, xScreen.y) * 0.9f, yBoundary.y, 0); newEnemy.position = newPos; //Put the enemy into the right parent objectMasterScript.AddChild(newEnemy); GeneralObject newEnemyScript = newEnemy.GetComponent <GeneralObject>(); if (newEnemyScript != null) { newEnemyScript.myAllianceState = AllianceState.Enemy; if (newEnemyScript.autoLaunch == false) { StartCoroutine(StartObject(newEnemyScript)); } //Adjust the enemy's stat if (enemyList[indx].myDamage != -1) { newEnemyScript.myDamage = enemyList[indx].myDamage; } if (enemyList[indx].curHealth != -1) { newEnemyScript.curHealth = enemyList[indx].curHealth; } if (enemyList[indx].maxHealth != -1) { newEnemyScript.maxHealth = enemyList[indx].maxHealth; } if (enemyList[indx].myValue != -1) { newEnemyScript.myValue = enemyList[indx].myValue; } if (enemyList[indx].mySpeed != -1) { newEnemyScript.mySpeed = enemyList[indx].mySpeed; } } return(true); } return(false); }
public void FireBullet(int bulletIndx, Transform toWhere = null) { Bullet bulletToShoot = bulletList[bulletIndx]; Transform curBullet = Instantiate(bulletToShoot.bullet, gunNozzle.position, Quaternion.identity).transform; Projectile curBulletScript = curBullet.GetComponent <Projectile>(); curBulletScript.fromWhere = gunNozzle.position; //Fire from the nozzle curBulletScript.mySpeed = bulletToShoot.shotForce; //Shot with some certain force if (bulletToShoot.damage != -1) { curBulletScript.myDamage = bulletToShoot.damage; //Set the damage as the gun's damage } curBulletScript.fromPlayer = fromPlayer; //Is the bullet fired from the player? if (bulletToShoot.lifeTime != -1) { curBulletScript.lifeTime = bulletToShoot.lifeTime; //Set the life time } curBulletScript.myForceMode = bulletToShoot.forceMode; if (bulletToShoot.speed > 0) { curBulletScript.mySpeed = bulletToShoot.speed; } curBulletScript.startDelay = bulletToShoot.startDelay; //Set the delay before we actually start bulletMasterScript.AddChild(curBullet); //Add the bullet to the bullet collector if (bulletToShoot.useCustomColor == true) //Change the color of the bullet { curBulletScript.ChangeColor(bulletToShoot.bulletOverlapColor); } if (bulletToShoot.rageReward > -1) { curBulletScript.rageReward = bulletToShoot.rageReward; } //Dynamically set alliance state for the bullet GeneralObject bulletScript = curBullet.GetComponent <GeneralObject>(); if (bulletScript != null) { bulletScript.myAllianceState = myAllianceState; } if (toWhere != null && curBulletScript.hasTarget == false) { curBulletScript.toWhere = toWhere.position; curBulletScript.hasTarget = true; } }
IEnumerator SpawnCoroutine() { for (int indx = 0; indx < numOfSpawn; indx++) { int spawnIndx = Random.Range(0, collectibleList.Count); int spawnChance = Random.Range(0, 100); //If we get the chance within the spawnChance range, then spawn it if (spawnChance <= collectibleList[spawnIndx].spawnChance) { //Instantiate Transform newCollectible = Instantiate(collectibleList[spawnIndx].myCollectible, collectibleMaster.transform); //Put the object into the master GeneralObject newColScript = newCollectible.GetComponent <GeneralObject>(); if (newCollectible != null && newColScript != null) { collectibleMaster.AddChild(newCollectible); //Calculate the position Vector3 spawnPos = transform.position; spawnPos.x = Random.Range(xScreen.x, xScreen.y); //Should the collectible be ally or enemy? int state = Random.Range(0, 2); if (state == 0) { newColScript.myAllianceState = AllianceState.Ally; spawnPos.y = yBoundary.y - 0.5f; } else { newColScript.myAllianceState = AllianceState.Enemy; spawnPos.y = yBoundary.x + 0.5f; } newCollectible.position = spawnPos; } } yield return(new WaitForSeconds(spawnObjDelay)); } yield return(new WaitForSeconds(waveWait)); spawnCoroutine = null; StartSpawn(); }
public virtual void CreateExplosion(Vector3 position) { if (myExplosion.Count > 0) { foreach (Transform explosion in myExplosion) { if (explosion == null) { return; } Transform curExplosion = Instantiate(explosion, position, Quaternion.identity); if (vfxMasterScript != null) { vfxMasterScript.AddChild(curExplosion); } } } }
IEnumerator SpawnCoroutine() { curWave++; for (int indx = 0; indx < allyPerWave; indx++) { if (isRandom == true) { spawnIndx = Random.Range(0, allyList.Count); } //ADD CODE TO SUPPORT SPAWNING FROM OTHER SIDES AND DIRECTION! Vector3 spawnPos = transform.position; spawnPos.y = yBoundary.x - 5; spawnPos.x = Random.Range(xBoundary.x, xBoundary.y); Transform newAlly = Instantiate(allyList[spawnIndx], allyColectorScript.transform); newAlly.position = spawnPos; GeneralObject newEnemyScript = newAlly.GetComponent <GeneralObject>(); if (newAlly != null && newEnemyScript != null) { allyColectorScript.AddChild(newAlly); } yield return(new WaitForSeconds(allyWaitTime)); } yield return(waveWaitTime); if (numberOfWave == -1) //Infinitely spawning { curWave = 0; spawnCoroutine = StartCoroutine(SpawnCoroutine()); } else { if (curWave < numberOfWave) { spawnCoroutine = StartCoroutine(SpawnCoroutine()); } else { spawnCoroutine = null; } } }