public Hazzard GetPooledObject() { Hazzard h = poolList[index]; index = (index + 1) % poolList.ToArray().Length; return(h); }
// Update is called once per frame void Update() { transform.LookAt(planet); if (waveStart) { if (elapsedTime < waitTime) { //Indicator.enabled = true; if (!blink) { StartCoroutine(DangerAnimationTimed()); } elapsedTime += Time.deltaTime; //Vector2 npos = Camera.main.WorldToScreenPoint(transform.position); //Vector2 sc = new Vector2(Screen.width / 2, Screen.width / 2); //Vector2 fpos = npos; //fpos.x = Mathf.Clamp(fpos.x, 100, Screen.width - 100); //fpos.y = Mathf.Clamp(fpos.y, 100, Screen.height - 100); //Indicator.rectTransform.position = fpos; } else { //Indicator.enabled = false; if (currentSpawn < spawn) { if (!fire) { float yoffset = Random.Range(-yOffset, yOffset); ////GameObject g = Instantiate(hazzard, transform.position + transform.up * yoffset, Quaternion.identity); //float size=Random.Range(1.51915f, 4f); float size = Random.Range(sizeVariance.x, sizeVariance.y); //g.transform.localScale = new Vector3(size, size, size); //g.GetComponent<Rigidbody2D>().AddForce(transform.forward * Random.Range(speedVariance.x, speedVariance.y), ForceMode2D.Impulse); Hazzard h = HazzardPool.GetPooledObject(); h.Begin(transform.position + transform.up * yoffset); h.SetSize(new Vector3(size, size, size)); h.Fire(transform.forward * Random.Range(speedVariance.x, speedVariance.y)); fire = true; if (currentSpawn == ufoSpawn && SpawnUFO) { //Spawn uFO //Debug.Log("SPAWN UFO"); //GameObject u = Instantiate(ufo, new Vector2(-27, 17), Quaternion.identity); //u.GetComponent<Ufo>().SetRandomStartPoint(); UFO_script.Revitalize(); UFO_script.SetRandomStartPoint(); } currentSpawn++; } else { elapsed += Time.deltaTime; if (elapsed >= spawnTimeDelay) { elapsed = 0; fire = false; } } } else { if (!handle) { StartCoroutine(DelayEnd()); } //END OF WAVE //waveEnd = true; } } } //Indicator //Vector2 d = transform.position - planet.position; //Indicator.rectTransform.localPosition = Vector2.zero; //Indicator.rectTransform.localPosition = (Vector2)Indicator.rectTransform.localPosition + d.normalized * 300; ////Debug.Log(Indicator.transform.position); //Debug.Log(Camera.main.WorldToScreenPoint(transform.position)); }
// Use this for initialization void Start() { switch (poolType) { case PoolType.Hazzard: for (int i = 0; i < Amount; i++) { GameObject g = Instantiate(pooledObject, transform.position, Quaternion.identity, transform); Hazzard h = g.GetComponent <Hazzard>(); h.Reset(); poolList.Add(h); } break; case PoolType.Projectile: for (int i = 0; i < Amount; i++) { GameObject g = Instantiate(pooledObject, transform.position, Quaternion.identity, transform); Projectile h = g.GetComponent <Projectile>(); h.gameObject.SetActive(false); projectileList.Add(h); //h.Reset(); //poolList.Add(h); } break; case PoolType.EnemyProjectile: for (int i = 0; i < Amount; i++) { GameObject g = Instantiate(pooledObject, transform.position, Quaternion.identity, transform); EnemyProjectile h = g.GetComponent <EnemyProjectile>(); h.gameObject.SetActive(false); eProjectileList.Add(h); //h.Reset(); //poolList.Add(h); } break; case PoolType.Tower: for (int i = 0; i < Amount; i++) { GameObject g = Instantiate(pooledObject, transform.position, Quaternion.identity, transform); TowerInterface h = g.transform.GetComponentInChildren <TowerInterface>(); towerInterfaceList.Add(h); g.SetActive(false); towerList.Add(g); //h.Reset(); //poolList.Add(h); } TowerListSum = towerList.ToArray().Length; if (readyTowers) { towerList[0].transform.position = readyTower1.position; towerList[0].transform.rotation = readyTower1.rotation; towerList[0].SetActive(true); towerList[1].transform.position = readyTower2.position; towerList[1].transform.rotation = readyTower2.rotation; towerList[1].SetActive(true); index = 2; } break; case PoolType.Collectable: for (int i = 0; i < Amount; i++) { GameObject g = Instantiate(pooledObject, transform.position, Quaternion.identity, transform); TowerInterface h = g.transform.GetComponentInChildren <TowerInterface>(); //towerInterfaceList.Add(h); g.SetActive(false); collectableList.Add(g); //h.Reset(); //poolList.Add(h); } break; } }