/// <summary> /// Update is called every frame, if the MonoBehaviour is enabled. /// </summary> void Update() { if (!canShoot && Input.GetAxisRaw("Fire1") == 0) { timerShoot.Stop(); canShoot = true; } if (Input.GetAxis("Fire1") > 0 && !timerShoot.Running) { //Save position Vector3 position = transform.position; position.x += PositionOffset; // Load a bullet in the pool GameObject bullet = PoolObjects.Get_Object(PoolObjects.PoolBullets, PoolObjects.PrefabBullet); // Locate the butte on the Ship bullet.transform.position = position; // Enable in the scene bullet.SetActive(true); // Start to move the bullet bullet.GetComponent <Bullet>().StartMoving(Color.red); AudioManager.Play(AudioClipName.Shoot); //Start the cooldown timerShoot.Duration = GameConstants.TimeForShoot; timerShoot.Run(); canShoot = false; } }
/// <summary> /// /// </summary> private void Awake() { unityEvents.Add(EventName.DifficultyUpEvent, new DifficultyUpEvent()); EventManager.AddInvoker(EventName.DifficultyUpEvent, this); PoolObjects.InitializePool(); }
/// <summary> /// Processes trigger collisions with other game objects /// </summary> /// <param name="other">information about the other collider</param> void OnTriggerEnter2D(Collider2D other) { // if colliding with teddy bear, add score, destroy teddy bear, // and return self to pool if (other.gameObject.CompareTag(TagName.Player.ToString()) && spriteRenderer.color != Color.red) { Instantiate(prefabExplosion, other.gameObject.transform.position, Quaternion.identity); Instantiate(prefabExplosion, transform.position, Quaternion.identity); unityEvents[EventName.TakeDamageEvent].Invoke(GameConstants.DamageBullet); PoolObjects.Return_Object(PoolObjects.PoolBullets, gameObject); //AudioManager.Play(AudioClipName.Explosion); } else if (other.gameObject.CompareTag(TagName.UFO.ToString()) && spriteRenderer.color == Color.red) { // if colliding with teddy bear projectile, destroy projectile and // return self to pool Instantiate(prefabExplosion, other.gameObject.transform.position, Quaternion.identity); Instantiate(prefabExplosion, transform.position, Quaternion.identity); PoolObjects.Return_Object(PoolObjects.PoolBullets, gameObject); PoolObjects.Return_Object(PoolObjects.PoolUFOs, other.gameObject); //AudioManager.Play(AudioClipName.Explosion); } else if (other.gameObject.CompareTag(TagName.Bullet.ToString()) && spriteRenderer.color != other.gameObject.GetComponent <SpriteRenderer>().color) { Instantiate(prefabExplosion, other.gameObject.transform.position, Quaternion.identity); Instantiate(prefabExplosion, transform.position, Quaternion.identity); PoolObjects.Return_Object(PoolObjects.PoolBullets, gameObject); PoolObjects.Return_Object(PoolObjects.PoolBullets, other.gameObject); //AudioManager.Play(AudioClipName.Explosion); } }
/// <summary> /// Spawns a new bird at a random location /// </summary> void SpawnUFO() { // generate random location location.y = Random.Range(minSpawnY, maxSpawnY); SetMinAndMax(location); // make sure we don't spawn into a collision int spawnTries = 1; while (Physics2D.OverlapArea(min, max) != null && spawnTries < MaxSpawnTries) { // change location and calculate new rectangle points location.y = Random.Range(minSpawnY, maxSpawnY); SetMinAndMax(location); spawnTries++; } // create new bird if found collision-free location if (Physics2D.OverlapArea(min, max) == null) { GameObject ufo = PoolObjects.Get_Object(PoolObjects.PoolUFOs, prefabUFO); ufo.transform.position = location; ufo.SetActive(true); ufo.GetComponent <UFO>().StartMoving(); } }
/// <summary> /// Update is called every frame, if the MonoBehaviour is enabled. /// </summary> void Update() { if (!cooldownTimer.Running && canShoot) { //Save position Vector3 position = transform.position; position.x -= PositionOffset; // Load a bullet in the pool GameObject bullet = PoolObjects.Get_Object(PoolObjects.PoolBullets, PoolObjects.PrefabBullet); // Locate the butte on the Ship bullet.transform.position = position; // Enable in the scene bullet.SetActive(true); // Start to move the bullet bullet.GetComponent <Bullet>().StartMoving(Color.green); //AudioManager.Play(AudioClipName.Shoot); //Start the cooldown cooldownTimer.Duration = Random.Range(GameConstants.UfoMinShotDelay, GameConstants.UfoMaxShotDelay); cooldownTimer.Run(); canShoot = false; } if (!canShoot && cooldownTimer.Running) { canShoot = true; } }
public static Platform SpawnPlatform(ref Transform parent) { var platform = PoolObjects.Get <Platform>(); platform.Transform.SetParent(parent); return(platform); }
public static Wall SpawnWall(ref Transform parent) { var wall = PoolObjects.Get <Wall>(); wall.Transform.SetParent(parent); return(wall); }
/// <summary> /// Genera una columna /// </summary> private void SpawColumn() { GameObject go = PoolObjects.GetObject(PoolObjects.PoolColumns, _prefabColumn); TypeColumn(go); go.SetActive(true); go.GetComponent <Column>().StartMoving(); }
private void Start() { for (var i = 0; i < PoolInformations.Length; i++) { var poolInfo = PoolInformations[i]; PoolManager.Instance.AddPool(PoolObjects.Create(poolInfo.PoolTag, poolInfo.PoolObject, poolInfo.Size)); } }
void Start() { EventManager.Initialize(); ScreenUtils.Initialize(); PoolObjects.InitializeUFOPool(); PoolObjects.InitializeBulletPool(); Instantiate(Resources.Load <GameObject>("Ship") as GameObject); }
public static Ball SpawnBall(ref Transform parent) { var ball = PoolObjects.Get <Ball>(); ball.Transform.SetParent(parent); ball.transform.position = Vector3.zero; return(ball); }
private static void ReleaseAllBoosters() { for (var i = 0; i < BoostersInMap.Count; i++) { PoolObjects.Release(BoostersInMap[i]); } BoostersInMap.Clear(); }
private void Start() { poolObjects = new PoolObjects(); rooms = new List <CellPosition>(); normalWallScale = new Vector3(1, 1, 0.1f); mFloor = PlayerPrefs.GetInt("LastReachedFloor", 1); SetFloor(mFloor); }
/// <summary> /// Reset is called when the user hits the Reset button in the Inspector's /// context menu or when adding the component the first time. /// </summary> public void Reset() { PoolObjects.ReturnPoolObjects(PoolObjects.PoolUFOs, TagName.UFO.ToString()); PoolObjects.ReturnPoolObjects(PoolObjects.PoolBullets, TagName.Bullet.ToString()); Time.timeScale = 1; AudioManager.Play(AudioClipName.ButtonReset); SceneManager.LoadScene(0); }
private void Awake() { if (instance != null && instance != this) { Destroy(this.gameObject); } else { instance = this; } }
public PoolableObject Get() { if (PoolObjects.Count > 0) { var pooledObject = PoolObjects.Dequeue(); pooledObject.ResetState(); return(pooledObject); } return(CreateNewPoolableObject()); }
private static void ReleaseEnemy() { for (var i = 0; i < EnemyInGame.Count; i++) { var enemy = EnemyInGame[i]; EnemyReleased?.Invoke(enemy); PoolObjects.Release(enemy); } EnemyInGame.Clear(); }
/// <summary> /// Processes trigger collisions with other game objects /// </summary> /// <param name="other">information about the other collider</param> void OnTriggerEnter2D(Collider2D other) { // if colliding with teddy bear, add score, destroy teddy bear, // and return self to pool if (other.gameObject.CompareTag(TagName.Player.ToString())) { //unityEvents[EventName.PointsAddedEvent].Invoke(ConfigurationUtils.BearPoints); Instantiate(prefabExplosion, other.gameObject.transform.position, Quaternion.identity); Instantiate(prefabExplosion, transform.position, Quaternion.identity); PoolObjects.Return_Object(PoolObjects.PoolUFOs, gameObject); } }
private static Enemy SpawnEnemy() { var enemy = PoolObjects.Get <Enemy>(); enemy.Transform.SetParent(_enemyContainer); enemy.Speed = _currentEnemySpeed; enemy.Transform.position = GetRandomPosition; EnemyInGame.Add(enemy); EnemySpawned?.Invoke(enemy); return(enemy); }
void spawnBullet() { //To get a specific item from the poolable list //PoolObjectItem item = PoolManagerScript.singleton.itemsToPool.Find(x => x.itemName == "laserRed"); //PoolObjects _pooledObject = PoolManagerScript.singleton.GetObjectFromPool(item.objectToPool); //To a random item from the poolable list PoolObjects _pooledObject = PoolManager.Instance.GetObjectFromPool(PoolManager.Instance.itemsToPool[Random.value > 0.5 ? 0 : 1].objectToPool); //Enabling item from the pool PoolManager.Instance.EnableObjectFromPool(_pooledObject, PoolManager.Instance.parentGameObject.transform.position, PoolManager.Instance.parentGameObject.transform.rotation); }
private void ReuseObject(PoolableObject pooledObject) { if (PoolSizeType == PoolSizeType.Fixed && PoolObjects.Count >= MaximumSize) { MonoBehaviour.Destroy(pooledObject); } else { pooledObject.gameObject.SetActive(false); pooledObject.transform.parent = PooledObjectsContainer; PoolObjects.Enqueue(pooledObject); } }
/// <summary> /// Инициализация класса анимации действи над предметами /// </summary> /// <param name="fieldSize">Размер поля для создания пула под количество ячеек</param> public void Initialization(int fieldSize) { if (_pool == null) { var folder = new GameObject("[PoolFolder]").transform; _pool = new PoolObjects(_prefab, folder, fieldSize); } _canvas = GetComponentInParent <Canvas>(); if (_canvas == null) { throw new System.NullReferenceException("[GameAnimations] Canvas not found"); } }
/// <summary> /// Recursively adds a tail to this or one of the next tails, /// dependat on which tail needs a next tail. /// </summary> public TailingObject AddTail() { if (NextTail) { return(NextTail.AddTail()); } PoolObjects _pooledObject = PoolManager.Instance.GetObjectFromPool("Tail"); //Enabling item from the pool GameObject tail = PoolManager.Instance.EnableObjectFromPool(_pooledObject, transform.position, Quaternion.identity, playerBehaviour.gameObject); _nextTail = tail.GetComponent <TailingObject>(); _nextTail.GetComponent <BoxCollider>().enabled = false; return(_nextTail); }
public override void RespawnBall() { if (_currentCountLooseBools == CountLooseBoolsMax) { PageManager.Open <MainMenuPage>(); return; } PoolObjects.Release(_ball); _ball = Spawner.SpawnBall(ref _ballContainer); _currentCountLooseBools++; base.RespawnBall(); }
private void TypeTwo(float positionY) { GameObject columnUp = PoolObjects.GetObject(PoolObjects.PoolColumns, _prefabColumn); columnUp.transform.localScale = _SCALE_INVERSE; //CONST float otherY = Random.Range(positionY + 12.5f, 9.5f); //CONST columnUp.transform.position = new Vector2(12, otherY); //CONST columnUp.SetActive(true); Column script = columnUp.GetComponent <Column>(); script.StartMoving(); script.DisableEdgeCollider(); }
private void GenerateGrid() { if (genericGround == null) { return; } if (GameManage.DonnerInstance.Carte == null) { return; } x = (int)GameManage.DonnerInstance.Carte.Xmax; y = (int)GameManage.DonnerInstance.Carte.Ymax; int origineX = -((x) / 2); int origineY = -((y) / 2); if (solGenerique == null) { solGenerique = new PoolObjects(); solGenerique.SetGameObject = genericGround; solGenerique.SetParentGameObject = this.transform; } Carte carte = GameManage.DonnerInstance.Carte; for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { if (carte.DonnerCellule(i, j) != null && carte.DonnerCellule(i, j).EstOccupe) { int ht = carte.DonnerCellule(i, j).Hauteur; for (int a = 0; a <= ht; a++) { solGenerique.CreerObject(new Vector3(origineX + i * h, a, origineY + j * w), Quaternion.identity); } } } } }
private static BaseBooster GetRandomBooster() { var randomValue = Random.Range(1, 4); switch (randomValue) { case 1: return(PoolObjects.Get <AddScore>()); case 2: return(PoolObjects.Get <SuperSpeed>()); case 3: return(PoolObjects.Get <GodMode>()); } Debug.LogError("BoosterType not found " + randomValue); return(PoolObjects.Get <AddScore>()); }
private void EndGameServer() { _movementController?.GameEnded(); _clientMovementController?.GameEnded(); _gameEndedController?.GameEnded(); _movementController = null; _clientMovementController = null; _gameEndedController = null; for (var i = 0; i < _walls.Length; i++) { if (_walls[i] == null) { continue; } PoolObjects.Release(_walls[i]); _walls[i] = null; } }
void OnTriggerEnter(Collider other) { //Check tag if (other.CompareTag("Player") && isPlayerShot || other.CompareTag("shot")) { return; } //particle if (impactFX == null) { impactFX = GameObject.Find("Pools/_PoolFXStarExplosion").GetComponent <PoolObjects>(); } else { impactFX.MakeGameObject(transform.position, Quaternion.identity); } //print("HIT: " + other.name); gameObject.SetActive(false); }
public override void EndGame() { _movementController.GameEnded(); _movementController = null; _gameEndedController.GameEnded(); _gameEndedController = null; for (var i = 0; i < Platforms.Length; i++) { PoolObjects.Release(Platforms[i]); Platforms[i] = null; } for (var i = 0; i < _walls.Length; i++) { PoolObjects.Release(_walls[i]); _walls[i] = null; } PoolObjects.Release(_ball); }