本文整理汇总了C#中UnityEngine.Collider2D.CompareTag方法的典型用法代码示例。如果您正苦于以下问题:C# Collider2D.CompareTag方法的具体用法?C# Collider2D.CompareTag怎么用?C# Collider2D.CompareTag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Collider2D
的用法示例。
在下文中一共展示了Collider2D.CompareTag方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnTriggerEnter2D
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);
}
示例2: OnTriggerEnter2D
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);
}
}
示例3: OnTriggerStay2D
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;
}
}
}
示例4: OnTriggerEnter2D
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");
}
}
示例5: OnTriggerExit2D
// Gets called when the groundCheck exits something
void OnTriggerExit2D(Collider2D col)
{
player.grounded = false;
if (col.CompareTag("Ground") || col.CompareTag("Platform"))
player.canDoubleJump = true;
}
示例6: OnTriggerExit2D
void OnTriggerExit2D(Collider2D hitObject)
{
if (hitObject.CompareTag("Terrain") || hitObject.CompareTag("Breakable"))
{
isGrounded = false;
}
}
示例7: OnTriggerEnter2D
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();
}
}
示例8: OnTriggerEnter2D
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);
}
}
示例9: OnTriggerEnter2D
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);
}
}
示例10: OnTriggerEnter2D
void OnTriggerEnter2D(Collider2D other) {
if (other.CompareTag ("Player") || other.CompareTag ("Clone")) {
keyCarrier = other.gameObject;
FollowCarrier ();
ResizeKey ();
}
}
示例11: OnTriggerExit2D
void OnTriggerExit2D(Collider2D col)
{
if (!col.CompareTag ("Grav") && !col.CompareTag("Respawn") && !col.CompareTag("Checkpoint") && !col.CompareTag("StopAI")) {
player.grounded = false;
player.time = 0;
}
}
示例12: OnTriggerStay2D
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;
}
}
}
}
示例13: OnTriggerEnter2D
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);
}
}*/
}
}
示例14: OnTriggerEnter2D
void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag ("NormalArrow") || other.CompareTag ("SplittedArrow")) {
nnflag = true;
transform.FindChild("Heart").gameObject.SetActive(true);
}
}
示例15: OnTriggerEnter2D
void OnTriggerEnter2D(Collider2D other) {
if (other.CompareTag ("Player") || other.CompareTag ("Clone")) {
presentMovement = other.GetComponent<GridMovement> ();
presentMovement.IncrementDestinationByCurrentDirection ();
}
}