当前位置: 首页>>代码示例>>C#>>正文


C# Collider2D.CompareTag方法代码示例

本文整理汇总了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);
    }
开发者ID:chups2themax,项目名称:CSE440,代码行数:35,代码来源:ZombieController.cs

示例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);
        }
    }
开发者ID:v0o0v,项目名称:Shooter,代码行数:34,代码来源:EnemyController.cs

示例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;
         }
     }
 }
开发者ID:eaho1,项目名称:Jasper-Samurai,代码行数:25,代码来源:PlayerFeetCollision.cs

示例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");
        }
    }
开发者ID:fatdai,项目名称:TestUnity2D,代码行数:31,代码来源:ZombieController.cs

示例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;
    }
开发者ID:ucsdCSE110wi16,项目名称:CSE110M240T15,代码行数:8,代码来源:GroundCheck.cs

示例6: OnTriggerExit2D

 void OnTriggerExit2D(Collider2D hitObject)
 {
     if (hitObject.CompareTag("Terrain") || hitObject.CompareTag("Breakable"))
     {
         isGrounded = false;
     }
 }
开发者ID:eaho1,项目名称:Jasper-Samurai,代码行数:7,代码来源:PlayerFeetCollision.cs

示例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();
        }

    }
开发者ID:NinghanHuang,项目名称:Space-shooter-V1.00,代码行数:30,代码来源:playercollider.cs

示例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);
        }
    }
开发者ID:fredsa,项目名称:unity-grid-defender,代码行数:31,代码来源:AmmunitionController.cs

示例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);
        }
    }
开发者ID:v0o0v,项目名称:Shooter,代码行数:32,代码来源:BossController.cs

示例10: OnTriggerEnter2D

	void OnTriggerEnter2D(Collider2D other) {
		if (other.CompareTag ("Player") || other.CompareTag ("Clone")) {
			keyCarrier = other.gameObject;
			FollowCarrier ();
			ResizeKey ();
		}
	}
开发者ID:deweytyl,项目名称:Elsewhere,代码行数:7,代码来源:Key.cs

示例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;
		}
	}
开发者ID:Magneseus,项目名称:Flipside,代码行数:7,代码来源:groundCheck.cs

示例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;
                }
            }
        }
    }
开发者ID:LamentedHarp44,项目名称:Night_Owls_GriffinTGT,代码行数:29,代码来源:InteractionAlertBehavior.cs

示例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);
                }
            }*/
        }
    }
开发者ID:BeNeNuTs,项目名称:Breaking-Blood-Cells,代码行数:30,代码来源:BoundsManager.cs

示例14: OnTriggerEnter2D

 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.CompareTag ("NormalArrow") || other.CompareTag ("SplittedArrow")) {
         nnflag = true;
         transform.FindChild("Heart").gameObject.SetActive(true);
     }
 }
开发者ID:Armour,项目名称:LoveArrow,代码行数:7,代码来源:NnControl.cs

示例15: OnTriggerEnter2D

	void OnTriggerEnter2D(Collider2D other) {
		if (other.CompareTag ("Player") || other.CompareTag ("Clone")) {
			presentMovement = other.GetComponent<GridMovement> ();

			presentMovement.IncrementDestinationByCurrentDirection ();
		}
	}
开发者ID:deweytyl,项目名称:Elsewhere,代码行数:7,代码来源:Ice.cs


注:本文中的UnityEngine.Collider2D.CompareTag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。