public void ShootThree() { if (isDead) { return; } GameObject go; int noOfBullets = 16; for (int i = 0; i < noOfBullets; i++) { bossBullet.TryGetNextObject(transform.position, Quaternion.identity, out go); //go = Instantiate(bullet, transform.position, Quaternion.identity); go.transform.Rotate(new Vector3(0, 0, 360 / noOfBullets * i)); } }
private void doEffect(Vector3 pos, Quaternion rot) { if (impactEffectPool == null) { SetupPool(); } GameObject g; if (impactEffectPool.TryGetNextObject(pos, rot, out g)) { AudioSource audioSource = g.GetComponent <AudioSource>(); if (Sounds.Length > 0) { if (!audioSource) { Debug.LogWarning("EffectImpact " + name + " has sounds defined but the template has no audio source!"); return; } audioSource.PlayOneShot(Sounds[Random.Range(0, Sounds.Length)]); } } }
private void doEffect(Vector3 pos, Vector3 dir, Transform parent, AudioSource audio) { if (muzzleEffectPool == null) { SetupPool(); } GameObject g; if (muzzleEffectPool.TryGetNextObject(pos, Quaternion.LookRotation(dir), out g)) { if (parent != null) { g.transform.parent = parent; } } if (audio) { if (Sounds.Length < 0) { Debug.LogWarning("EffectMuzzleFlash " + name + " is given an audio source but has no sounds to play!"); return; } audio.PlayOneShot(Sounds[Random.Range(0, Sounds.Length - 1)]); } }
IEnumerator SpawnNoteDelay() { yield return(new WaitForSeconds((beatDuration - animTime) / 1000f)); //Debug.Log("Note spawned at " + SpawnPoint.position); musicNotePool.TryGetNextObject(SpawnPoint.position, Quaternion.identity); }
public void EnemyDestroyed(Enemy enemy) { if (explosionsPool.TryGetNextObject(enemy.transform.position, Quaternion.identity, out GameObject explosionGO)) { GameManager.Instance.DesactivateOnTime(explosionGO, 0.06f); } AudioManager.Instance.PlayEnemyExplosionLow(); if (!IsFinalLevel()) { enemiesleft--; if (enemiesleft % 3 == 0) { MakeCrazyEnemy(); } if (enemiesleft % 10 == 0) { SetAnimationSpeed(animationSpeed + 0.5f); } if (enemiesleft == 0) { GameManager.Instance.LevelCompleted(); } else if (enemiesleft == 1) { SetAnimationSpeed(animationSpeed * 2); } } }
// Use this for initialization void Start() { pool = GetComponent <EZObjectPool>(); if (pool.TryGetNextObject(spawnPos[Mathf.RoundToInt(Random.Range(0, 8))].position, Quaternion.identity, out obj)) { obj.SetActive(true); } }
void ShootRed() { redBulletPool.TryGetNextObject(transform.position, transform.rotation); //if (redBulletPool.TryGetNextObject(transform.position, transform.rotation, out bullet)) { // print("APPLE"); // bullet.GetComponent<Bullet>().bulletInitialVelocity = 50f; //} }
public void ShootOne() { if (isDead) { return; } GameObject go; int noOfBullets = 4; offset = (offset + offsetIncrease) % 360; for (int i = 0; i < noOfBullets; i++) { bulletPool.TryGetNextObject(transform.position, Quaternion.identity, out go); //go = Instantiate(bullet, transform.position, Quaternion.identity); go.transform.Rotate(new Vector3(0, 0, 360 / noOfBullets * i + offset)); } }
void Update() { if (objectPool.TryGetNextObject(transform.position + Random.insideUnitSphere * 0.1f, transform.rotation, out g)) { r = g.GetComponent <Rigidbody>(); r.AddForce(transform.up * 450f + Random.insideUnitSphere * 50f); } }
public void Shoot() { if (isShootAvailable() && playerShots.TryGetNextObject(GetGunPosition(), Quaternion.identity, out GameObject go)) { go.GetComponent <Rigidbody2D>().velocity = Vector2.up * stats.shootSpeed * 10; lastTimeShot = Time.time; AudioManager.Instance.PlayPlayerShot(); } }
public void FoodTaken(Vector3 food) { if (isDead) { return; } audioManager.PlaySound("Food"); foodExplosionPool.TryGetNextObject(food, Quaternion.identity); }
void Shoot() { if (bullets.TryGetNextObject(outPosition.position, transform.rotation, out obj)) { obj.GetComponent <Rigidbody>().AddForce((obj.transform.right * -1) * 1000f); } canShoot = false; shootCooldown = 0; }
void Start() { if (shellPool.TryGetNextObject(Vector3.zero, Quaternion.identity, out shell)) { print(shellPool.AvailableObjectCount() == 9); print(shellPool.ActiveObjectCount() == 1); } //shellPool.TryGetNextObject }
void Disparar() { if (Time.time > timeLastShot) { GameObject disparoTEMP; disparosPool.TryGetNextObject(ObtenerPuntoDisparo(), transform.rotation, out disparoTEMP); disparoTEMP.GetComponent <Rigidbody2D>().velocity = transform.up * velocidadDisparo; timeLastShot = Time.time + delayDisparo; } }
private void attack() { GameObject bulletSpawned; if (bulletPool.TryGetNextObject(firePoint.position, firePoint.rotation, out bulletSpawned)) { Rigidbody2D rb = bulletSpawned.GetComponent <Rigidbody2D>(); rb.AddForce(firePoint.right * bulletSpeed, ForceMode2D.Impulse); } }
void makeMail(string mailId) { GameObject mailObject; if (mailPool.TryGetNextObject(Vector3.zero, Quaternion.identity, out mailObject)) { MailController mailController = mailObject.GetComponent <MailController>(); mailController.Init(mailDb.getMailByID(mailId)); usedMails.Add(mailController); } }
public void crearObjeto(int x, int y, int z) { Vector3 posicion = new Vector3(espacio_cubo * x + xinicio, 0, espacio_cubo * z + zinicio); Vector3 posicionfacil = new Vector3(espacio_cubo * x, espacio_cubo * y, espacio_cubo * z); RaycastHit hit_arribaizquierda; RaycastHit hit_arribaderecha; RaycastHit hit_abajoizquierda; RaycastHit hit_abajoderecha; Listarayos.Clear(); if (Physics.Raycast(new Vector3(espacio_cubo * x + xinicio - 0.5f, espacio_cubo * y + yinicio, espacio_cubo * z + zinicio + 0.5f), Vector3.down, out hit_arribaizquierda, 600, layer)) { Listarayos.Add(hit_arribaizquierda.point.y); //posicion.y = hit.point.y +y*espacio_cubo + 1.5f; } if (Physics.Raycast(new Vector3(espacio_cubo * x + xinicio + 0.5f, espacio_cubo * y + yinicio, espacio_cubo * z + zinicio + 0.5f), Vector3.down, out hit_arribaderecha, 600, layer)) { Listarayos.Add(hit_arribaderecha.point.y); } if (Physics.Raycast(new Vector3(espacio_cubo * x + xinicio - 0.5f, espacio_cubo * y + yinicio, espacio_cubo * z + zinicio - 0.5f), Vector3.down, out hit_abajoizquierda, 600, layer)) { Listarayos.Add(hit_abajoizquierda.point.y); } if (Physics.Raycast(new Vector3(espacio_cubo * x + xinicio + 0.5f, espacio_cubo * y + yinicio, espacio_cubo * z + zinicio - 0.5f), Vector3.down, out hit_abajoderecha, 600, layer)) { Listarayos.Add(hit_abajoderecha.point.y); } posicion.y = Listarayos.Min() + y * espacio_cubo + 0.5f; Color color = new Color(Random.value, Random.value, Random.value); GameObject outobject; if (objectPool.TryGetNextObject(posicion, Quaternion.identity, out outobject)) { //instanciacubovirtual[x, y, z] = outobject; //instanciacubovirtual[x, y, z].name = string.Format("{0}.virtual", this.id); //setPropertyColor(color, instanciacubovirtual[x, y, z]); Instanciaobjetoprinciapl = new Objeto_principal(color, posicionfacil); //Objprincipal.Add(Instanciaobjetoprinciapl.id, Instanciaobjetoprinciapl); this.id = idAhora++; /* * if(idAhora > 1200 && Objeto_principal.idAhora > 1200) * { * idAhora = 0; * Objeto_principal.idAhora = 0; * } */ outobject.name = string.Format("{0}.virtual", this.id); setPropertyColor(color, outobject); Posicion.Add(posicionfacil, outobject); outobject.GetComponent <MeshRenderer>().enabled = true; } }
private void doEffect(Vector3 pos, Vector3 dir, float dist) { GameObject g; if (tracerEffectPool.TryGetNextObject(pos, Quaternion.LookRotation(dir), out g)) { ParticleSystem p = g.GetComponent <ParticleSystem>(); p.startSpeed = Speed; p.startLifetime = dist / Speed; } }
public void add(string message, Vector3 pos, eLevel level) { GameObject newCombatText; pool.TryGetNextObject(pos, Quaternion.identity, out newCombatText); float angle = Mathf.Clamp(ejectionAngle + UnityEngine.Random.Range(-spreadAngle * 0.5f, spreadAngle * 0.5f), -180, 180); CombatText pooledCombatText = newCombatText.GetComponent <CombatText>(); pooledCombatText.Init(message, duration, speed, angle); }
void SpawnZombie() { Transform spawnPosition = spawnPoints[Random.Range(0, spawnPoints.Count)].transform; GameObject zombie; if (zombiePool.TryGetNextObject(spawnPosition.position, spawnPosition.rotation, out zombie)) { zombie.GetComponent <CapsuleCollider>().enabled = true; zombie.GetComponent <Rigidbody>().isKinematic = false; zombie.GetComponent <ZombieHealth>().zombieHealth = 60f; Debug.Log("Spawned"); } }
void SpawnMinion() { Transform spawnPosition = spawnPoints[Random.Range(0, spawnPoints.Count)].transform; GameObject minion; if (minionPool.TryGetNextObject(spawnPosition.position, spawnPosition.rotation, out minion)) { minion.GetComponent <CapsuleCollider>().enabled = true; minion.GetComponent <Rigidbody>().isKinematic = false; minion.GetComponent <MinionHealth>().minionHealth = 90f; Debug.Log("Spawned"); } }
// Update is called once per frame void Update() { currentTime += Time.deltaTime; if (currentTime > freqTime) { for (int i = 0; i <= freqObject; i++) { if (pool.TryGetNextObject(spawnPos[Mathf.RoundToInt(Random.Range(0, 8))].position, Quaternion.identity, out obj)) { obj.SetActive(true); } } currentTime = 0; } }
public void SpawnFood(Vector3 enemy, Vector3 bullet) { if (isDead) { return; } if (Random.Range(0f, 1f) < foodDrop) { foodPool.TryGetNextObject(enemy, Quaternion.identity); } audioManager.PlaySound("FoodAppear"); audioManager.PlaySound("Explosion"); enemyExplosionPool.TryGetNextObject(enemy, Quaternion.identity); bulletExplosionPool.TryGetNextObject(bullet, Quaternion.identity); }
private void InsertMeteor() { Vector3 position = StartPosition.transform.position; float rx = (float)Random.Range(-(StartAreaX / 3), StartAreaX / 3); float ry = (float)Random.Range(-(StartAreaY / 3), StartAreaY / 3); float rz = 0f; if (ZLevels != null) { int len = ZLevels.Length; int index = (int)Random.Range(0, len); rz = ZLevels[index]; } GameObject go = null; objectPool.TryGetNextObject(new Vector3(position.x + rx, position.y + ry, rz), new Quaternion(), out go); //Debug.Log ("scaleX = " + scale.x.ToString() + " scaleY = " + scale.y.ToString() + " rx = " + rx + " ry = " + ry); if (go != null) { MeteorSpriteObj objectScript = go.GetComponent <MeteorSpriteObj> (); float speedRange = (float)Random.Range(-SpeedRange, SpeedRange); float speed = WindSpeed + speedRange; float ex = EndPosition.transform.position.x; float ey = EndPosition.transform.position.y; float offsetx = (float)Random.Range(-(EndAreaX / 3f), EndAreaX / 3f); float offsety = (float)Random.Range(-(EndAreaY / 3f), EndAreaY / 3f); objectScript.StartColor = StartColor; objectScript.TravelColor = TravelColor; objectScript.ExplodeColor = ExplodeColor; objectScript.StartAnim(ex + offsetx, ey + offsety, rz, speed); //float endPointX = ex + offsetx; //float endPointY = ey + offsety; //Debug.Log ("offsetx = " + offsetx + " offsety = " + offsety + " endPointX = " + endPointX + " endPointY = " + endPointY); } }
public void SpawnObject(SpawnType spawnType, int trafficLaneId) { GameObject outObject = null; switch (spawnType) { case SpawnType.CAR: if (carObjectPool.TryGetNextObject(Vector3.one, Quaternion.identity, out outObject)) { TrafficManager.Instance.InitEntityAtLane(trafficLaneId, outObject); } break; case SpawnType.BICYCLE: if (bicycleObjectPool.TryGetNextObject(Vector3.one, Quaternion.identity, out outObject)) { TrafficManager.Instance.InitEntityAtLane(trafficLaneId, outObject); } break; case SpawnType.BUS: if (busObjectPool.TryGetNextObject(Vector3.one, Quaternion.identity, out outObject)) { TrafficManager.Instance.InitEntityAtLane(trafficLaneId, outObject); } break; case SpawnType.PEDESTRIAN: if (pedestrianObjectPool.TryGetNextObject(Vector3.one, Quaternion.identity, out outObject)) { TrafficManager.Instance.InitEntityAtLane(trafficLaneId, outObject); } break; case SpawnType.TRAIN: if (trainObjectPool.TryGetNextObject(Vector3.one, Quaternion.identity, out outObject)) { TrafficManager.Instance.InitEntityAtLane(trafficLaneId, outObject); } break; default: break; } }
private void AddButton(SelectorButton action) { GameObject obj; if (objectPool.TryGetNextObject(Vector3.zero, Quaternion.identity, out obj)) { var btn = obj.GetComponent <CustomUIButton>(); btn.ClearListeners(); btn.AddClickListener(CloseSelector); btn.AddClickListener(action.action); btn.SetText(action.title); obj.transform.SetParent(buttonContainer.transform, false); obj.transform.SetAsLastSibling(); } }
public void OnDrop(PointerEventData eventData) { GameObject item; var draggableObject = eventData.pointerDrag.GetComponent <DraggableObjectBehavior>(); if (draggableObject != null) { if (draggableObject.DragIndicator.CurrentGlowState == ObjectGlowState.Default) { if (!draggableObject.moveToFinalPosition) { if (objectPool.TryGetNextObject(draggableObject.DragIndicator.transform.position, Quaternion.identity, out item)) { draggableObject.MixtureItem.OnDrop(); item.GetComponent <DropZoneObjectHandler>().Setup(draggableObject); item.transform.SetParent(this.transform); item.transform.localScale = new Vector3(draggableObject.MixtureItem.Scale, draggableObject.MixtureItem.Scale); } else { Debug.Log("Unable to generate object for dropped item"); } } else { draggableObject.transform.position = draggableObject.DragIndicator.transform.position; } } else if (draggableObject.DragIndicator.CurrentGlowState == ObjectGlowState.Valid) { // perform mix item operations // dropped object will be mixed with the collider if (draggableObject.DragIndicator.GetLastCollider() is DropZoneObjectHandler) { SimulationMixtureManager.instance.AddMixableToMixture((draggableObject.DragIndicator.GetLastCollider() as DropZoneObjectHandler), draggableObject); Debug.Log("Mixed " + draggableObject.DragIndicator.GetLastCollider().MixtureItem.itemName + " with " + draggableObject.MixtureItem.itemName); } else { Debug.LogWarning("Unknown state detected"); } } } }
private GameObject CreateMenuButton(Vector3 position, UnityEngine.Events.UnityAction callback, string buttonText = "Mix") { GameObject obj = null; if (objectPool.TryGetNextObject(position, Quaternion.identity, out obj)) { var btn = obj.GetComponent <Button>(); obj.transform.SetParent(contextMenuPanel.transform, false); btn.onClick.RemoveAllListeners(); btn.onClick.AddListener(CleanMenuPanel); btn.onClick.AddListener(callback); btn.GetComponent <CustomUIButton>().SetText(buttonText); } return(obj); }
IEnumerator Shoot() { while (true) { while (target != null && Vector2.Distance(transform.position, target.transform.position) < m_Range) { GameObject bulletObj; m_pool.TryGetNextObject(shooting.position, weapon.rotation, out bulletObj); Bullet bullet = bulletObj.GetComponent <Bullet>(); bullet.SetDamage(m_Damage); bullet.SetSprite(m_BulletSprite); bullet.Shoot(); yield return(new WaitForSeconds(1 / m_ShootSpeed)); } yield return(null); } }
public void BreakBreakable(Transform oldBreakable, Vector2 hitDir) { string breakableName = oldBreakable.name.Split(' ')[0]; if (breakableName.Contains("Barrel")) { int breakableSortingOrder = oldBreakable.GetComponent <SpriteRenderer>().sortingOrder; if (breakingBarrelsPool.TryGetNextObject(oldBreakable.position, oldBreakable.rotation, out GameObject newBreaking)) { newBreaking.transform.position = oldBreakable.position; oldBreakable.gameObject.SetActive(false); StartCoroutine(ReciclateBarrel(newBreaking, hitDir, breakableSortingOrder)); } } else { //Destroy(oldBreakable.gameObject); } }