Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Intro_Scritping/ShipShooter/Assets/Scripts/EnemySpawner.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
88 lines (72 sloc)
3.15 KB
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 UnityEngine; | |
using System.Collections; | |
public class EnemySpawner : MonoBehaviour { | |
//Numbers | |
public int randomNum = 0; | |
//Enemy Spawns | |
public GameObject enemy1_left1; | |
public int enemy1count = 0; | |
public GameObject enemy1_left2; | |
public GameObject enemy1_left3; | |
public GameObject enemy1_right1; | |
public GameObject enemy1_right2; | |
public GameObject enemy1_right3; | |
//vectors | |
public Vector3 spawn1 = new Vector3(-17.0f, 17.0f, 5.0f); | |
public Vector3 spawn2 = new Vector3(-14.0f, 17.0f, 5.0f); | |
public Vector3 spawn3 = new Vector3(-11.0f, 17.0f, 5.0f); | |
public Vector3 spawn4 = new Vector3(-8.0f, 17.0f, 5.0f); | |
public Vector3 spawn5 = new Vector3(-5.0f, 17.0f, 5.0f); | |
public Vector3 spawn6 = new Vector3(-2.0f, 17.0f, 5.0f); | |
public Vector3 spawn7 = new Vector3(1.0f, 17.0f, 5.0f); | |
public Vector3 spawn8 = new Vector3(4.0f, 17.0f, 5.0f); | |
public Vector3 spawn9 = new Vector3(7.0f, 17.0f, 5.0f); | |
public Vector3 spawn10 = new Vector3(10.0f, 17.0f, 5.0f); | |
public Vector3 spawn11 = new Vector3(13.0f, 17.0f, 5.0f); | |
public Vector3 spawn12 = new Vector3(16.0f, 17.0f, 5.0f); | |
//Enemy Types | |
public GameObject enemy1; | |
public GameObject enemy2; | |
// Use this for initialization | |
void Start () { | |
randomNum = 1; | |
} | |
public void Onslaught() | |
{ | |
randomNum = 1; | |
StartCoroutine(EnemySpawn()); | |
} | |
// Update is called once per frame | |
void Update () { | |
if (randomNum > 0) | |
Onslaught(); | |
} | |
//IEnumerator | |
IEnumerator EnemySpawn() | |
{ | |
if (enemy1count < 1) | |
{ | |
if (randomNum == 1) | |
{ | |
Debug.Log("Enumerator Starts"); | |
enemy1count = 1; | |
enemy1_left1 = (GameObject)Instantiate(enemy1, spawn1, Quaternion.identity); | |
enemy1_right1 = (GameObject)Instantiate(enemy1, spawn1, Quaternion.identity); | |
iTween.MoveTo(enemy1_left1, iTween.Hash("path", iTweenPath.GetPath("LeftCurve1"), "time", 10)); | |
iTween.MoveTo(enemy1_right1, iTween.Hash("path", iTweenPath.GetPath("RightCurve1"), "time", 10)); | |
yield return new WaitForSeconds(0.2f); | |
enemy1_left2 = (GameObject)Instantiate(enemy1, spawn2, Quaternion.identity); | |
enemy1_right2 = (GameObject)Instantiate(enemy1, spawn2, Quaternion.identity); | |
iTween.MoveTo(enemy1_left2, iTween.Hash("path", iTweenPath.GetPath("LeftCurve2"), "time", 10)); | |
iTween.MoveTo(enemy1_right2, iTween.Hash("path", iTweenPath.GetPath("RightCurve2"), "time", 10)); | |
yield return new WaitForSeconds(0.2f); | |
enemy1_left3 = (GameObject)Instantiate(enemy1, spawn3, Quaternion.identity); | |
enemy1_right3 = (GameObject)Instantiate(enemy1, spawn3, Quaternion.identity); | |
iTween.MoveTo(enemy1_left3, iTween.Hash("path", iTweenPath.GetPath("LeftCurve3"), "time", 10)); | |
iTween.MoveTo(enemy1_right3, iTween.Hash("path", iTweenPath.GetPath("RightCurve3"), "time", 10)); | |
Debug.Log("enumerator Ends"); | |
} | |
} | |
yield return new WaitForSeconds(1f); | |
} | |
} |