void OnTriggerStay2D(Collider2D other) { if (!other.gameObject.CompareTag ("Player") && !other.gameObject.CompareTag ("Untagged") && !other.gameObject.CompareTag ("Floor") && !other.gameObject.CompareTag("GrappleHook") && !other.gameObject.CompareTag("GrappleGun")) { if (UndetectedSearchPurchased == false) { if (other.CompareTag ("PatrollingGuard") && inUse && other.gameObject.GetComponent<GuardBehavior> ().currState != ENMY_STATES.SEARCH && other.gameObject.GetComponent<GuardBehavior> ().currState != ENMY_STATES.ATTACK) { other.gameObject.GetComponent<GuardBehavior> ().targPos = this.transform.position; other.gameObject.GetComponent<GuardBehavior> ().ChangeENMYState (ENMY_STATES.SEARCH); } else if (other.CompareTag ("Malformed Patient") && inUse && other.gameObject.GetComponent<ExperimentBehavior>().state != ENMY_STATES.ATTACK) { other.gameObject.GetComponent<ExperimentBehavior> ().state = ENMY_STATES.ATTACK; } else if (other.CompareTag ("Dog") && inUse && other.gameObject.GetComponentInParent<DogBehavior> ().state != ENMY_STATES.SEARCH && other.gameObject.GetComponentInParent<DogBehavior> ().state != ENMY_STATES.ATTACK) { other.gameObject.GetComponentInParent<DogBehavior> ().target = this.transform.position; other.gameObject.GetComponentInParent<DogBehavior> ().state = ENMY_STATES.SEARCH; } } } }
void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag ("NormalArrow") || other.CompareTag ("SplittedArrow")) { nnflag = true; transform.FindChild("Heart").gameObject.SetActive(true); } }
// Gets called when the groundCheck exits something void OnTriggerExit2D(Collider2D col) { player.grounded = false; if (col.CompareTag("Ground") || col.CompareTag("Platform")) player.canDoubleJump = true; }
public void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("enemy")) { this.enemy.Play(); Debug.Log("enemy collider"); this.gameController.LivesValue -= 10; enemyctrl c = other.GetComponent<enemyctrl>(); c.Reset(); } if (other.CompareTag("health")) { this.health.Play(); Debug.Log("health collider"); this.gameController.LivesValue += 10; enemyctrl c = other.GetComponent<enemyctrl>(); c.Reset(); } if (other.CompareTag("Rock")) { this.Rock.Play(); Debug.Log("Rock collider"); this.gameController.ScoreValue += 20; enemyctrl c = other.GetComponent<enemyctrl>(); c.Reset(); } }
void OnTriggerEnter2D(Collider2D other) { Debug.Assert (other.CompareTag ("Enemy") || other.CompareTag ("Enemy Obstacle") || other.CompareTag ("Worldbox"), other.gameObject.name); if (other.CompareTag ("Worldbox")) { return; } int points = 10; Color otherColor = other.transform.GetChild (0).gameObject.GetComponent<MeshRenderer> ().material.color; otherColor.a = 1f; if (Time.time > nextAllowedExplosionTime) { nextAllowedExplosionTime = Time.time + minTimeBetweenExplosions; GameObject explosion = Instantiate (explosionPrefab, other.transform.position, Quaternion.identity) as GameObject; explosion.GetComponentInChildren<ParticleSystem> ().startColor = otherColor; explosion.GetComponentInChildren<TextMesh> ().color = otherColor; explosion.GetComponentInChildren<TextMesh> ().text = string.Format (Constants.pointsFormat, points); } if (other.CompareTag ("Enemy")) { GameObject mine = Instantiate (minePrefab, other.transform.position, Quaternion.identity) as GameObject; mine.transform.parent = other.transform.parent; mine.transform.GetChild (0).GetComponent<MeshRenderer> ().material.color = otherColor; mine.transform.GetChild (1).GetComponent<MeshRenderer> ().material.color = otherColor; } Destroy (other.gameObject); gameController.AddPoints (points); if (--hitPoints <= 0) { gameObject.SetActive (false); } }
void OnTriggerEnter2D( Collider2D other ) { if(other.CompareTag("cat")) { GetComponent<AudioSource>().PlayOneShot(catContactSound); Transform followTarget = congaLine.Count == 0 ? transform : congaLine[congaLine.Count-1]; other.transform.parent.GetComponent<CatController>().JoinConga( followTarget, moveSpeed, turnSpeed ); congaLine.Add( other.transform ); if (congaLine.Count >= 5) { Debug.Log("You won!"); Application.LoadLevel("WinScene"); } } else if(!isInvincible && other.CompareTag("enemy")) { GetComponent<AudioSource>().PlayOneShot(enemyContactSound); isInvincible = true; timeSpentInvincible = 0; for( int i = 0; i < 2 && congaLine.Count > 0; i++ ) { int lastIdx = congaLine.Count-1; Transform cat = congaLine[ lastIdx ]; congaLine.RemoveAt(lastIdx); cat.parent.GetComponent<CatController>().ExitConga(); } if (--lives <= 0) { Debug.Log("You lost!"); Application.LoadLevel("LoseScene"); } } }
void OnTriggerEnter2D(Collider2D other) { // When collided with tag name "Enemy" or "EnemyMissile", does nothing. if (other.CompareTag(_enemyString) || other.CompareTag(_enemyMissileString)) return; // Change sprite to damage sprite. if (damagedSprite != null) { _sprite.sprite = damagedSprite; Invoke("SetNormalSprite", 0.05f); } // reduce hp. hp -= 30f; // when boss dead, start next enemy wave and show destroy effect. if (hp <= 0f) { // Player Gets Score. _scoreManager.CountScore(300); // start next enemy wave. _spawnManager.StartNextState(); // show destroy effect. ObjectPool.Instance.GetObject(_boomBossString, transform); // return boss object to pool object manager. ObjectPool.Instance.ReturnObject(bossPoolName, transform.parent); } }
void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag ("Player") || other.CompareTag ("Clone")) { keyCarrier = other.gameObject; FollowCarrier (); ResizeKey (); } }
public int team; // 0 for enemy projectile, 1 for player #endregion Fields #region Methods void OnTriggerEnter2D(Collider2D coll) { if((team==1) && coll.CompareTag("Enemy")) { if(coll.GetComponent<BomberControl>()!=null) { coll.GetComponent<BomberControl>().TakeDamage(damage); } else if(coll.GetComponent<BasicEnemyControl>()!=null) { coll.GetComponent<BasicEnemyControl>().TakeDamage(damage); } else if(coll.GetComponent<ArtilleryControl>()!=null) { coll.GetComponent<ArtilleryControl>().TakeDamage(damage); } else if(coll.GetComponent<BossControl>()!=null) { coll.GetComponent<BossControl>().TakeDamage(damage); } if(damageNumber!=null) { Instantiate(damageNumber, coll.transform.position, Quaternion.identity); } } if((team==0) && (coll.CompareTag("Player"))) { coll.GetComponent<PlayerControl>().TakeDamage(damage); } }
public void OnTriggerEnter2D(Collider2D collider) { if (collider.CompareTag("Background")) { move(collider); } if (collider.CompareTag("Ground")) { move(collider); } if (collider.CompareTag("Pipe")) { move(collider); } if (collider.CompareTag("Pipe1")) { if (pipeCount % 2 == 0) { RandomizePipes1(collider); pipeCount++; } else { RandomizePipes2(collider); pipeCount++; } } }
void OnTriggerExit2D(Collider2D col) { if (!col.CompareTag ("Grav") && !col.CompareTag("Respawn") && !col.CompareTag("Checkpoint") && !col.CompareTag("StopAI")) { player.grounded = false; player.time = 0; } }
void OnTriggerExit2D(Collider2D other) { if (other.CompareTag("Environment") || other.CompareTag("Hookable")) { inTrigger = 0; } }
void OnTriggerExit2D(Collider2D hitObject) { if (hitObject.CompareTag("Terrain") || hitObject.CompareTag("Breakable")) { isGrounded = false; } }
void OnTriggerStay2D(Collider2D hitObject) { if (hitObject.CompareTag("Terrain")) { isGrounded = true; } if (hitObject.CompareTag("Breakable")) { if (player.smashing) { Collider2D[] hits = Physics2D.OverlapCircleAll((Vector2)this.transform.position + this.GetComponent<CircleCollider2D>().offset, .4f); foreach (Collider2D hit in hits) { if (hit.CompareTag("Breakable")) { Destroy(hit.transform.parent.parent.gameObject); } } } else { isGrounded = true; } } }
void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("Player") && moveBlock && transform.position.y < player.transform.position.y) { startMoving = true; anim.SetBool("blockTouched", startMoving); } if (other.CompareTag("Player") && pushBlock && player.wallCheck) { startMoving = true; anim.SetTrigger("pushBlock"); } if (other.CompareTag("Player") && riseBlock) { triggerHit++; if (triggerHit >= riseAmount) { //other.transform.parent = currentPos; startMoving = true; anim.SetTrigger("riseBlock"); } } }
void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag ("Player") || other.CompareTag ("Clone")) { presentMovement = other.GetComponent<GridMovement> (); presentMovement.IncrementDestinationByCurrentDirection (); } }
void OnTriggerEnter2D(Collider2D collider) { if(collider.CompareTag(Tags.destructibleObject)){ collider.gameObject.GetComponent<DestructibleObject>().takeDamage(damage); if(destroyOnHitDestructibleObject){ Destroy(gameObject); } } if(collider.CompareTag(Tags.enemy)){ EnemyLife enemyLife = collider.gameObject.GetComponent<EnemyLife>(); HitAnEnemy(enemyLife); } if(collider.CompareTag(Tags.enemyExtraCollider)){ EnemyLife enemyLife = collider.gameObject.GetComponent<EnemyExtraCollider>().enemyLifeToUse; HitAnEnemy(enemyLife); } if(collider.CompareTag(Tags.scenarioObject)){ if(destroyOnHitScenarioObject){ Destroy(gameObject); } } if(collider.CompareTag(Tags.wall)){ if(destroyOnHitWall){ Destroy(gameObject); } } }
void OnTriggerEnter2D(Collider2D coll) { if (!coll.CompareTag ("GrappleGun") && !coll.CompareTag("GrappleHook") && !coll.CompareTag("Untagged") && !coll.CompareTag("Boss") && !coll.CompareTag("GrappleHookStart")) { if (elevators.Count != 0) { for (int i = 0; i < elevators.Count; ++i) { if (elevators[i] != null && elevators[i] != null && elevators [i].gameObject.GetComponent<ElevatorBehavior> ().user == coll.gameObject) return; } } // The temporary elevator will spawn at the unit's feet, and then // be added to the elevators array. GameObject tempElevator; // The elevator needs to be spawned at a very specific point // X-value: center of the ladder // Y-value: bottom of the player collision/unit // Z-value: 0.0f Vector3 spawnPoint = new Vector3 (GetComponent<Transform> ().position.x, coll.GetComponent<Transform> ().position.y, 0.0f); tempElevator = Instantiate (prefab, spawnPoint, Quaternion.identity) as GameObject; tempElevator.GetComponent<ElevatorBehavior> ().parent = this.gameObject; tempElevator.GetComponent<ElevatorBehavior> ().user = coll.gameObject; elevators.Add (tempElevator); } }
void OnTriggerEnter2D(Collider2D other) { // Reset (); if(other.CompareTag("Enemy") == true || other.CompareTag("Minion") == true) { //get a particle object from the object pooler GameObject go = bulletParticlePooler.GetComponent<ObjectPooler>().GetPooledObject(); go.transform.position = transform.position; go.SetActive(true); other.GetComponent<EnemyGeneralBehaviour>().hpCount -= bulletDamage; if(target.GetComponent<EnemyGeneralBehaviour>().targetedBullet != null){ target.GetComponent<EnemyGeneralBehaviour>().targetedBullet = null; } else{ } if(target != null){ target = null; } else{ } gameObject.SetActive(false); GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>().comboCount += 1; hasForce = false; force = Vector2.zero; myRigidbody.velocity = Vector2.up* 20f; } }
public override void ApplyEffect(Collider2D collider) { if (collider.CompareTag("Player")) { ok = true; shield.Stop(); shield.volume = 0; GetComponent<CircleCollider2D>().radius = 30; if(PlayerPrefs.GetString("Dagon") == "Dagon") { random = Random.Range(0, getD.Length); AudioSource.PlayClipAtPoint(getD[random], transform.position, 1f); iTween.MoveTo(gameObject, iTween.Hash("position", new Vector3(0f,0f,0f), "islocal", true)); } else { random = Random.Range(0, getC.Length); AudioSource.PlayClipAtPoint(getC[random], transform.position, 1f); iTween.MoveTo(gameObject, iTween.Hash("position", new Vector3(1f,1f,0f), "islocal", true)); } StartCoroutine("Go"); AudioSource.PlayClipAtPoint(clip, transform.position, 0.5f); StartCoroutine("UsingMagnetic", tempo); } if (collider.CompareTag("Coin") && isInCharacter) { ChasePlayer followPlayer = collider.gameObject.AddComponent(typeof(ChasePlayer)) as ChasePlayer; } }
void OnTriggerEnter2D(Collider2D other) { if((other.CompareTag("Cell") && other.GetType() == typeof(BoxCollider2D)) || (other.CompareTag("Enemy") && other.GetType() == typeof(BoxCollider2D)) || (other.CompareTag("LTAux") && other.GetType() == typeof(BoxCollider2D))){ Vector3 reflect = Vector3.Reflect(other.transform.right, normal); Vector3 direction = new Vector3(reflect.x, reflect.y, 0); Vector3 diff = (other.transform.position + direction) - other.transform.position; /*if((normal.x*diff.x > 0) || (normal.y*diff.y > 0)) return;*/ float rot_z = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg; AgentMovement agentMovement = other.gameObject.GetComponent<AgentMovement>(); agentMovement.agentRigidbody.rotation = rot_z; //other.gameObject.GetComponent<Rigidbody2D>().AddForce(normal * 10); /*AgentMovement agentMovement = other.gameObject.GetComponent<AgentMovement>(); if(normal.x == 0f){ if(agentMovement.agentRigidbody.position.y >= transform.position.y + offset){ agentMovement.agentRigidbody.position = new Vector2(agentMovement.agentRigidbody.position.x, transform.position.y + offset); } }else{ if(agentMovement.agentRigidbody.position.x >= transform.position.x + offset){ agentMovement.agentRigidbody.position = new Vector2(transform.position.x + offset, agentMovement.agentRigidbody.position.y); } }*/ } }
void OnTriggerEnter2D(Collider2D c) { if (c.CompareTag("Hookable")) { partManag.SendMessage("generateSalivaSplash", transform.position + offsetToHookPoint); hookedObject = c.gameObject; offsetToHookPoint = transform.position - hookedObject.transform.position; offsetToHookPoint = Quaternion.Inverse(hookedObject.transform.rotation) * offsetToHookPoint; Rigidbody2D hookBody = GetComponent<Rigidbody2D>(); hookBody.isKinematic = true; hookBody.velocity = Vector3.zero; hookGun.HookOn(); GetComponent<CircleCollider2D>().enabled = false; } else if(!TagsToIgnore(c)) { hookGun.CancelHook(); } if (c.CompareTag("Edible")) { Destroy(c.gameObject); hookGun.CancelHook(); } }
private void OnTriggerEnter2D(UnityEngine.Collider2D collision) { if (collision.CompareTag("Glass")) { collision.GetComponent <ForGlassAnimat>().Break(); if (bloodSlider.value > 0) { bloodSlider.value -= 10; } // bloodSlider.value } else if (collision.CompareTag("Player")) { if (collision.name == "Player_1") { var rig = GetComponent <Rigidbody2D>(); //高速心扣血 if (rig.velocity.magnitude >= 13) { collision.GetComponent <Player1Life>().TakeDamage(); } return; } heartCount++; //Debug.Log("Character Name: "+MainCharacter.Instance.name); if (MainCharacter.Instance.isDashing == false) { //击退和击飞 switch (collision.name) { case "Foot": //print("jumpUp"); MainCharacter.Instance._playerVelocityY += collision.transform.localScale.x * sizeToJumpHeightRate; //MainCharacter.Instance._playerVelocityY = // Mathf.Min(MainCharacter.Instance._playerVelocityY, maxYSpeed); print("hit foot, final vertical speed: " + MainCharacter.Instance._playerVelocityY); //MainCharacter.Instance._canJump = 2; break; case "Body": // print("hitBack"); MainCharacter.Instance._playerVelocityX -= collision.transform.localScale.x * sizeToHitBackSpeedRate * hitBackSpeed; print("hit body, final horizontal speed: " + MainCharacter.Instance._playerVelocityX); break; } } PoolManager.RecycleHeart(this.gameObject); } }
void OnTriggerEnter2D(Collider2D other) { // when collided with tag name "Enemy" or "EnemyMissile" or "HpItem" or "PowerItem" or "BombItem", does nothing. if (other.CompareTag(_enemyString) || other.CompareTag(_enemyMissileString) || other.CompareTag(_hpItemString) || other.CompareTag(_powerItemString) || other.CompareTag(_bombItemString)) { return; } // change sprite to damage sprite. _enemySpriteAnim.Damaged(); // reduce hp. hp -= 60f; // when dead, player get score and given item according to it's percentage (default is 20%) if (hp <= 0f) { // player gets score. if (_scoreManager != null) _scoreManager.CountScore(100); // show Destroy Effect. ObjectPool.Instance.GetObject(_boom2String, transform); // Check whether item will be spawned or not. if (Random.Range(0f, 1f) < itemSpawnPercentage) { ObjectPool.Instance.GetObject(spawnItemPoolName[Random.Range(0, spawnItemPoolName.Length)], transform); } gameObject.SetActive(false); } }
void OnTriggerEnter2D(Collider2D other) { if(other.CompareTag("Cat")) { Transform followTarget = congaLine.Count == 0 ? transform : congaLine[congaLine.Count - 1]; other.GetComponent<CatController>().JoinConga(followTarget, moveSpeed, turnSpeed); congaLine.Add(other.transform); if (congaLine.Count >= 5) { Application.LoadLevel("WinScene"); } //Debug.Log("Oops. Stepped on a Cat."); } else if (!isInvincible && other.CompareTag("Enemy")) { isInvincible = true; timeSpentInvincible = 0; for(int i = 0; i <2 && congaLine.Count > 0; i++) { int lastIdx = congaLine.Count - 1; Transform cat = congaLine[lastIdx]; congaLine.RemoveAt(lastIdx); cat.parent.GetComponent<CatController>().ExitConga(); } //Debug.Log("Pardon me, ma'am"); } if(--lives <0) { Debug.Log("You lost!"); Application.LoadLevel("CongaScene"); } //Debug.Log("Hit" + other.gameObject); }
void OnTriggerEnter2D(Collider2D other) { if ((other.CompareTag ("Hero") || other.CompareTag ("Enemy")) && !other.GetComponent<HeroUnit> ().isHead && !isDead ()) { RectTransform rt = GetComponent<RectTransform> (); transform.position = new Vector2 (((int)Random.Range (-14, 15)) * rt.rect.width * rt.localScale.x, ((int)Random.Range (-10, 11)) * rt.rect.height * rt.localScale.y); } }
void OnTriggerEnter2D(Collider2D other) { //Debug.Log("Enter Hit " + other.gameObject); if (other.CompareTag ("cat")) { Transform followTarget = congaLine.Count == 0 ? transform : congaLine[congaLine.Count-1]; other.GetComponent<CatController> ().JoinConga (followTarget,moveSpeed,turnSpeed); congaLine.Add (other.transform); } else if (other.CompareTag ("enemy") && !isInvincible) { isInvincible = true; timeSpentInvincible = 0; for (int i = 0; i < 2 && congaLine.Count > 0; ++i) { int lastIndex = congaLine.Count - 1; Transform cat = congaLine [lastIndex]; congaLine.RemoveAt (lastIndex); cat.GetComponent<CatController> ().ExitConga (); } if (--lives <= 0) { Debug.Log ("You lost!"); Application.LoadLevel ("LoseScene"); } } if (congaLine.Count >= 5) { Debug.Log ("You win!"); Application.LoadLevel ("WinScene"); } }
void OnTriggerExit2D(Collider2D collider) { if (collider.CompareTag ("Bullet")|| collider.CompareTag ("EnemyBullet")|| collider.CompareTag("ToBeDestroyed")) { Destroy(collider.gameObject); } }
void OnTriggerEnter2D(Collider2D other) { if (shouldTeleport && (other.CompareTag ("Player") || other.CompareTag ("Clone"))) { destination.PrepareForLanding (); other.transform.position = destination.transform.position; other.GetComponent<GridMovement> ().ClearDestination (); } }
void OnTriggerStay2D(Collider2D c) { if (c.CompareTag ("asteroid") || c.CompareTag ("asteroid frag")) { Explosao.Spawn(transform.position); GetComponent<Rigidbody2D>().velocity = VelocityReduction * GetComponent<Rigidbody2D>().velocity.normalized*Velocity; c.gameObject.GetComponent<AsteroidController>().TakeDamage(Damage, c); } }
void OnTriggerExit2D(Collider2D other) { if (other.CompareTag("Environment") || other.CompareTag("Hookable")) { grounded = 0; GroundSensorChange(false); } }
private new void OnTriggerEnter2D(UnityEngine.Collider2D collision) { if (collision.tag.Contains("Terrain")) { gameObject.SetActive(false); } else if (collision.CompareTag("Player") || collision.CompareTag("Enemy")) { if (!(Enum.GetName(typeof(DamageSource), Source) == collision.tag)) { collision.gameObject.GetComponent <Character>().ReceiveAttack(new AttackInfo(Damage, KnockbackImpulse * transform.right, KnockbackTime, StunTime, Source)); NumPassed++; } } }
public void OnTriggerStay2D(UnityEngine.Collider2D collision) { if (collision.CompareTag("Player")) { insideSecret = true; } }
private void OnTriggerEnter2D(UnityEngine.Collider2D collision) { if (collision.CompareTag("Player")) { goalObject.SetActive(true); } }
public void OnTriggerExit2D(UnityEngine.Collider2D collision) { if (collision.CompareTag("Player")) { insideSecret = false; } }
private void OnTriggerEnter2D(UnityEngine.Collider2D collision) { if (collision.CompareTag("Player")) { collision.GetComponent <PlayerAllinOne>().TakeDamage(gameObject.GetComponentInParent <PangBoss>().damage); } }
void OnTriggerExit2D(UnityEngine.Collider2D collider) { if (collider.CompareTag("Enemy")) { enemyCountInTrigger -= 1; Debug.Log(enemyCountInTrigger + "/" + enemiesInBaseToLose + " enemies in trigger"); } }
void OnTriggerEnter2D(UnityEngine.Collider2D Other) { if (Other.CompareTag("Player")) { Destroy(gameObject); Destroy(Other.gameObject); GamePlay.PlayerDieShowPanel(); Time.timeScale = 1f; } }
void OnTriggerEnter2D(UnityEngine.Collider2D collision) { if (collision.CompareTag("Speed")) { Debug.Log("SpeedUp"); speed += .05f; speedUpCounter += 8; StartCoroutine("SpeedUpTimer"); Destroy(collision.gameObject); } }
protected void OnTriggerEnter2D(UnityEngine.Collider2D other) { if (other.CompareTag("Hostile")) { if (particleEffect) { Instantiate(particleEffect, other.transform.position + new Vector3(0, 2), Quaternion.identity); } var rb = other.GetComponent <Rigidbody2D> (); rb.velocity = Vector2.up * 0.5f * knockbackVelocity; if (movingRight) { rb.velocity += Vector2.right * knockbackVelocity; } else { rb.velocity += Vector2.left * knockbackVelocity; } } }