private void ShootBullet() { // grab a bullet from the object pool _currentBullet = _buildingPoolScript.GetPooledObject(); if (_currentBullet == null) { return; } // Set position _currentBullet.transform.position = firePoint.position; _currentBullet.transform.rotation = firePoint.rotation; // set color _bulletRenderer = _currentBullet.GetComponent <Renderer>(); _bulletRenderer.material.color = bulletColor; _currentBullet.SetActive(true); // FIRE AWAY! _fireCountdown = Time.deltaTime + fireRate; //Debug.Log("Shoot"); //GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation) as GameObject; //_bulletScript = bullet.GetComponent<Bullet>(); //_bulletScript.rangeRadius = rangeRadius; //_fireCountdown = Time.deltaTime + fireRate; }
/// <summary> /// This Method Grabs us a Fruit from the pool puts it in position and activates it. This method is /// called from the "LoadAndFireRandomFruit()" /// </summary> /// <returns></returns> public GameObject RetrieveFruitFromPool() { //new int named r get assigned a Random value between zero and the length of the array of objectPoolScript int r = Random.Range(0, fruitPoolScripts.Length); //objectPoolScript named tempPool gets accesses the elements in the array at position R ObjectPoolScript tempPool = fruitPoolScripts[r]; //new GameObject named obj and it calls GetPooledObejct on the tempPool. GameObject obj = tempPool.GetPooledObject(); //if obj is null.. if (obj == null) { //we return null... return(null); } //we set obj at our position... obj.transform.position = transform.position; //we set obj's rotation to 000 obj.transform.rotation = Quaternion.identity; //set the obj to active obj.SetActive(true); //then return the obj return(obj); }
void MultiTurtleCreator(int turtles, string type1, string type2, float posX, float startY, float scale) { for (int i = 0; i < turtles; i++) { if (Random.value > 0.5f) { turtlePool = TurtDecoder(type1); } else { turtlePool = TurtDecoder(type2); } turtle = turtlePool.GetPooledObject(); turtle.SetActive(true); turtle.transform.position = new Vector3(posX, startY, -1); if (Random.value > 0.5f) { turtle.transform.Rotate(new Vector3(0, 180, 0)); //turtle.transform.localScale += new Vector3 (-1, 0, 0); } turtle.transform.localScale += new Vector3(scale, scale, 0); AddTurtle(1); } }
public static Animator GetPooledAnimator(RuntimeAnimatorController animatorController = null) { GameObject gameObject = objectPool.GetPooledObject(); Animator animator = gameObject.GetComponent <Animator>(); animator.runtimeAnimatorController = animatorController; return(animator); }
private void ThrowItAway() { GameObject grenadeGameObject = projectilePool.GetPooledObject(); IProjectile grenade = grenadeGameObject.GetComponent <IProjectile>(); grenadeGameObject.transform.position = initialPosition; grenadeGameObject.transform.right = transform.right; grenade.Launch(this.victimTag); }
public GameObject RetrieveCloudFromPool() { GameObject obj; //new GameObject named obj and it calls GetPooledObejct on the tempPool. obj = cloud.GetPooledObject(); obj.SetActive(true); //objectPoolScript named tempPool gets accesses the elements in the array at position R return(obj); }
void FuseInGrid(float dist) { this.GetComponent <SpriteRenderer>().enabled = false; nearestDistance[dist].GetComponent <BubbleProperties>().isEmpty = false; nearestDistance[dist].GetComponent <BubbleProperties>().BubbleColor = this.BubbleColor; nearestDistance[dist].GetComponent <BubbleProperties>().SearchMatchingNeighbours(); nearestDistance[dist].GetComponent <BubbleProperties>().inStack = false; //nearestDistance[dist].GetComponent<SpriteRenderer>().sprite = sp.sprite; //nearestDistance[dist].GetComponent<SpriteRenderer>().enabled = true; //print(nearestDistance[dist].name); prev_Score = GamePrefs.lEVEL_SCORE; if (gameManager.colorMatcher.Count >= 2) { foreach (Transform temp in gameManager.colorMatcher) { GamePrefs.lEVEL_SCORE += 5; GameObject pop_anim = pop_pooler.GetPooledObject(); pop_anim.transform.position = temp.transform.position; pop_anim.transform.rotation = Quaternion.identity; pop_anim.transform.localScale = temp.transform.localScale; pop_anim.SetActive(true); temp.GetComponent <BubbleProperties>().isEmpty = true; } GameObject pop_anim_again = pop_pooler.GetPooledObject(); pop_anim_again.transform.position = nearestDistance[dist].transform.position; pop_anim_again.transform.rotation = Quaternion.identity; pop_anim_again.transform.localScale = nearestDistance[dist].transform.localScale; pop_anim_again.SetActive(true); nearestDistance[dist].GetComponent <BubbleProperties>().isEmpty = true; gameManager.OnMatch_three(); } gameManager.colorMatcher.Clear(); }
private void BadaBoom() { GameObject projectileGameObject = projectilePool.GetPooledObject(); IProjectile projectile = projectileGameObject.GetComponent <IProjectile>(); SlugPhysics projPhysic = projectileGameObject.GetComponent <SlugPhysics>(); projectileGameObject.transform.position = projectileInitialPos.position; projectile.Launch("Player"); projPhysic.SetVelocityX(transform.right.x * 0.4f); audioManager.PlaySound(2); }
void Start() { for (int i = 0; i < berserkersOnTheRoof.Length; i++) { GameObject berserkRoot = berserkerPool.GetPooledObject(); berserkRoot.transform.position = berserkerOnTheRoofPos[i].position; berserkersOnTheRoof[i] = berserkRoot.GetComponentInChildren <Berserker>(); berserkersOnTheRoof[i].SetWalkingMode(false); } colliderRamp.enabled = false; }
void Explode() { gameObject.SetActive(false); GameObject g = ops.GetPooledObject(); if (g != null) { g.transform.position = gameObject.transform.position; } g?.SetActive(true); g?.GetComponent <ExplosionScript>().StartExplosion(); }
/// <summary> /// This method moves StarPickUp into position and activates it. /// </summary> /// <param name="newPos"></param> /// <param name="yOffset"></param> public void GetStarObject(Vector3 newPos, float yOffset) { GameObject obj = starPoolScript.GetPooledObject(); if (obj == null) { return; } obj.transform.position = newPos + new Vector3(0, yOffset, 0); obj.transform.rotation = Quaternion.identity; obj.SetActive(true); }
public void Execute(string victimTag, Vector3 unused, Vector3 unused2) { anim.runtimeAnimatorController = attackAnimatorController; anim.SetTrigger("fire"); GameObject bulletGameObject = bullettPool.GetPooledObject(); bulletGameObject.transform.position = GetProjPosInit(); bulletGameObject.transform.right = movementManager.lookingDirection; IProjectile bullet = bulletGameObject.GetComponentInChildren <IProjectile>(); bullet.Launch(victimTag); audioManager.PlaySound(0); EventManager.TriggerEvent(GlobalEvents.GunUsed, 0); }
public void AEEndShootAnim() { smoke.SetActive(false); smoke.SetActive(true); GameObject missile = missilePool.GetPooledObject(); missile.transform.localPosition = missileInitialPos; missile.SetActive(true); GuidedMissile guidedMissile = missile.GetComponentInChildren <GuidedMissile>(); guidedMissile.speedFactor = speedFactor; missile.GetComponentInChildren <GuidedMissile>().speedFactor = speedFactor; shootInProgress = false; }
public void Throw(GameObject player, float spdx, float spdy) { GameObject g = ops.GetPooledObject(); if (g != null) { g.transform.position = player.transform.position; } g?.SetActive(true); g?.GetComponent <Rigidbody2D>()?.AddForce(new Vector3(spdx, spdy, 0)); BombScript bs = null; g?.TryGetComponent <BombScript>(out bs); bs?.BombSpawned(); }
public void Throw() { bool flipX = renderer.flipX; // LOG SPAWN GameObject magic = pool.GetPooledObject(); if (magic != null) { magic.transform.position = gameObject.transform.position; magic.GetComponent <MouseProjectileScript>().ResetTarget(Player); magic.SetActive(true); } animator.SetBool("Attack", false); AttackTime = 0; Attacked = false; }
void DelayForSelfCollision() { Spawnpoint.GetComponent <CircleCollider2D>().isTrigger = false; GameObject temp = RemainingPooler.GetPooledObject(); // Instantiate new bubble temp.SetActive(true); //Spawnpoint.gameObject.layer = LayerMask.NameToLayer("Falling"); temp.GetComponent <SpriteRenderer>().sprite = null; temp.GetComponent <CircleCollider2D>().isTrigger = true; Spawnpoint = temp.transform; // Replaces old spawnpoint transform with new projectile = temp.GetComponent <Rigidbody2D>(); if (GamePrefs.NO_OF_BUBBLES == 0) { Spawnpoint.GetComponent <SpriteRenderer>().enabled = false; } }
public void Throw() { bool flipX = renderer.flipX; // LOG SPAWN GameObject log = pool.GetPooledObject(); if (log != null) { log.transform.position = gameObject.transform.position; log.GetComponent <LogMovementScript>().Speed = new Vector3((flipX ? 10f : -10f), -10f, 0); log.SetActive(true); } animator.SetBool("ThrowLog", false); ThrowTime = 0; WasThrown = false; }
public void Throw() { bool flipX = renderer.flipX; GameObject arrow = pool.GetPooledObject(); if (arrow != null) { Vector2 toTarget = (new Vector2(Player.transform.position.x - gameObject.transform.position.x, Player.transform.position.y - gameObject.transform.position.y)).normalized; arrow.transform.position = gameObject.transform.position; arrow.GetComponent <GPProjectile>().ResetTarget(Player, toTarget.x * 15, toTarget.y * 15, 0.005f); arrow.SetActive(true); } animator.SetBool("Shoot", false); AttackTime = 0; Attacked = false; }
public void Throw() { bool flipX = renderer.flipX; GameObject magic = pool.GetPooledObject(); if (magic != null && Player != null) { Vector2 toTarget = new Vector2(Player.transform.position.x - ShootOrigin.transform.position.x, Player.transform.position.y - ShootOrigin.transform.position.y); Vector2 toTarget2 = new Vector2(toTarget.x, toTarget.y + toTarget.magnitude / 6f); toTarget2 = 12 * toTarget2.normalized; magic.transform.position = ShootOrigin.transform.position; magic.GetComponent <RatProjectileScript>().ResetTarget(Player, toTarget2.x, toTarget2.y, -2); magic.SetActive(true); } animator.SetBool("Attack", false); AttackTime = 0; Attacked = false; }
void OnCollisionEnter2D(Collision2D other) { print(other.gameObject.name); // SoundManager.Instance.DrumShot(); if (other.collider.name.Contains("Wasted")) { GamePrefs.temp_remaning_projectiles_shot++; //print("Remaining Count "); //Debug.Log(GamePrefs.temp_remaning_projectiles_shot); } iTween.ShakeScale(toShake, iTween.Hash("x", 0.1f, "y", 0.1f, "time", 0.2f, "ignoretimescale", true)); other.gameObject.SetActive(false); int prev_Score = GamePrefs.lEVEL_SCORE; GamePrefs.lEVEL_SCORE += ScoreToGive; GameObject temp = DrumPooler.GetPooledObject(); temp.transform.position = this.transform.position; temp.SetActive(true); }
/// <summary> /// This Method Grabs us a Bomb or a PowerUp from the pool puts it in position and activates it. This method is /// called from the "LoadAndFireOtherObject()" /// </summary> /// <param name="type"></param> /// <returns></returns> public GameObject RetrieveOtherFromPool(int type) { //create a ObjectPoolScript var and name it tempPool and then assign it the element at position "type" in the array. ObjectPoolScript tempPool = bombAndPowerUpPoolScripts[type]; //new gameObject "obj" gets a pooled object from tempPool reference using GetPooledObject. GameObject obj = tempPool.GetPooledObject(); //if the obj equals null... if (obj == null) { //return null return(null); } //the obj's position gets our position obj.transform.position = transform.position; //the obj's rotation gets our rotation obj.transform.rotation = transform.rotation; //the obj gets set active obj.SetActive(true); //return obj... return(obj); }
private void Shoot(Transform initTransform) { GameObject bulletGameObject = bullettPool.GetPooledObject(); bulletGameObject.transform.position = initTransform.position; bulletGameObject.transform.rotation = initTransform.rotation; if (withYoffset) { bulletGameObject.transform.Translate(0, 0.055f, 0, Space.Self); withYoffset = false; } else { withYoffset = true; } IProjectile bullet = bulletGameObject.GetComponentInChildren <IProjectile>(); bullet.Launch(vicTag); attackManager.UpdateBulletCount(); }
void SimulateTrajectory() { //Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); //transform.rotation = Quaternion.LookRotation(Vector3.forward, mousePos - transform.position); //if (transform.eulerAngles.z > this.maxLeftAngle && transform.eulerAngles.z < 180.0) //{ // transform.eulerAngles = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y, maxLeftAngle); //} //if (transform.eulerAngles.z < this.maxRightAngle && transform.eulerAngles.z > 180.0) //{ // transform.eulerAngles = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y, maxRightAngle); //} Vector2 velocity = pooled_Trajectory.transform.rotation * parent.transform.up * 100; pooled_Trajectory.gameObject.GetComponent <Rigidbody2D>().AddForce(velocity * 40); GameObject temp = pooler.GetPooledObject(); temp.SetActive(true); temp.transform.parent = pooled_Trajectory.transform.parent; temp.transform.localScale = pooled_Trajectory.transform.localScale; temp.GetComponent <Rigidbody2D>().velocity = Vector3.zero; pooled_Trajectory = temp; }
public void Spawn() { if (singleEnemyPrefab != null) { if (enemy == null) { InstantiateSingleEnemyPrefab(); } enemy.SetActive(true); enemy.transform.position = transform.position; } else if (enemyPool != null) { enemy = enemyPool.GetPooledObject(); enemy.transform.position = transform.position; } enemyHealthManager = enemy.GetComponentInChildren <HealthManager>(); if (spawnerType == SpawnerType.Manual && spawnAgainAtDeath) { spawnCoroutine = StartCoroutine(RespawnUponDeathCoroutine()); } if (spawnerType == SpawnerType.CameraBlocker) { CameraUtils.EnableFollow(false); StartCoroutine(AllowCameraFollowCoroutine()); } if (posToGoAtSpawn != null) { StartCoroutine(GoToCoroutine(posToGoAtSpawn.position.x)); } }
public AudioSource GetAudioSource() { return audioSourcePool.GetPooledObject().GetComponent<AudioSource>(); }
// Gonna work on it... void Connected_Nodes_Search_Initial_Call() { for (int i = 0; i < Num_Of_Columns; i++) { if (!MatrixGrid[0][i].GetComponent <BubbleProperties>().isEmpty) { FindConnectedNodes(MatrixGrid[0][i]); } } for (int i = 0; i < Num_Of_Rows; i++) { if (i % 2 == 0) { for (int j = 0; j < Num_Of_Columns; j++) { if (connected_Flag_Cell[i][j] && !(Remaining_Colors.Contains(MatrixGrid[i][j].GetComponent <BubbleProperties>().BubbleColor))) { Remaining_Colors.Add(MatrixGrid[i][j].GetComponent <BubbleProperties>().BubbleColor); } } } else { for (int j = 0; j < Num_Of_Columns - 1; j++) { if (connected_Flag_Cell[i][j] && !(Remaining_Colors.Contains(MatrixGrid[i][j].GetComponent <BubbleProperties>().BubbleColor))) { Remaining_Colors.Add(MatrixGrid[i][j].GetComponent <BubbleProperties>().BubbleColor); } } } } //Count For Cheers int falling_Count = 0; for (int i = 0; i < Num_Of_Rows; i++) { if (i % 2 == 0) { for (int j = 0; j < Num_Of_Columns; j++) { if (!connected_Flag_Cell[i][j]) { if (!MatrixGrid[i][j].GetComponent <BubbleProperties>().isEmpty) { GameObject temp = ObjectPool.GetPooledObject(); temp.transform.parent = MatrixGrid[i][j].transform.parent; temp.transform.position = MatrixGrid[i][j].transform.position; temp.transform.localScale = MatrixGrid[i][j].transform.localScale; temp.GetComponent <FallingBubbleScript>().BubbleColor = MatrixGrid[i][j].GetComponent <BubbleProperties>().BubbleColor; falling_Count++; temp.SetActive(true); int RandForce = UnityEngine.Random.Range(1000, 1200); ExplosionForce2D.AddExplosionForce(temp.GetComponent <Rigidbody2D>(), RandForce, Vector2.up, 5); MatrixGrid[i][j].GetComponent <BubbleProperties>().isEmpty = true; } } } } else { for (int j = 0; j < Num_Of_Columns - 1; j++) { if (!connected_Flag_Cell[i][j]) { if (!MatrixGrid[i][j].GetComponent <BubbleProperties>().isEmpty) { GameObject temp = ObjectPool.GetPooledObject(); temp.transform.parent = MatrixGrid[i][j].transform.parent; temp.transform.position = MatrixGrid[i][j].transform.position; temp.transform.localScale = MatrixGrid[i][j].transform.localScale; temp.GetComponent <FallingBubbleScript>().BubbleColor = MatrixGrid[i][j].GetComponent <BubbleProperties>().BubbleColor; falling_Count++; temp.SetActive(true); int RandForce = UnityEngine.Random.Range(1000, 1100); ExplosionForce2D.AddExplosionForce(temp.GetComponent <Rigidbody2D>(), RandForce, Vector2.up, 5); //print("Calling Fall Down..."); MatrixGrid[i][j].GetComponent <BubbleProperties>().isEmpty = true; ////; } } } } } CheckLevelCleared(); // Pivot check initialMid.SendMessage("MoveDown"); }