當前位置: 首頁>>代碼示例>>C#>>正文


C# Collision類代碼示例

本文整理匯總了C#中Collision的典型用法代碼示例。如果您正苦於以下問題:C# Collision類的具體用法?C# Collision怎麽用?C# Collision使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Collision類屬於命名空間,在下文中一共展示了Collision類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: OnCollisionEnter

	void OnCollisionEnter(Collision col)
	{
		if(side==BulletSide.FRIENDLY)
		{
			if(col.gameObject.tag==TagsStorage.ABIL_SHIELD)
				deactivate();
			
			if(col.gameObject.tag==TagsStorage.ENEMY_TAG)
			{
				col.gameObject.GetComponent<EnemySpaceship>().Attacked(damage);
				deactivate();
			}
		}
		
		if(side==BulletSide.ENEMY)
		{
			if(col.gameObject.tag==TagsStorage.FRIENDLY_TAG)
			{
				col.gameObject.GetComponent<FriendlySpaceship>().Attacked(damage);
				deactivate();
			}
			if(col.gameObject.tag==TagsStorage.ABIL_SHIELD)
				deactivate();
		}
		
		if(col.gameObject.tag==TagsStorage.ASTEROID_TAG)
			deactivate();
	}
開發者ID:tiempo8,項目名稱:spacetactics20,代碼行數:28,代碼來源:BulletContainer.cs

示例2: OnCollisionEnter

    void OnCollisionEnter(Collision col)
    {
        if (col.gameObject.name == "Wall")
        {
            Destroy (gameObject);

        }
        else if (col.gameObject.name == "BlueVirus"){
            bVirus = col.gameObject.GetComponent<BlueVirus>();
            bVirus.takeDamage (1,1);
            Destroy (gameObject);
        }
        else if (col.gameObject.name == "RedVirus"){
            Destroy (gameObject);
        }
        else if (col.gameObject.name == "GreenVirus"){
            gVirus = col.gameObject.GetComponent<GreenVirus>();
            gVirus.takeDamage (1,1);
            Destroy (gameObject);
        }else if(col.gameObject.name == "Boss"){
            boss = col.gameObject.GetComponent<BossScript>();
            boss.takeDamage(1, 1);
            Destroy(gameObject);
        }
    }
開發者ID:TStream,項目名稱:MiniPhD,代碼行數:25,代碼來源:LazerBeam.cs

示例3: OnCollisionEnter

    void OnCollisionEnter(Collision col)
    {
        if (col.gameObject.tag == "Ammo")
        {
            vie--;
            if (vie <= 0)
            {
                isDead = true;
                anim.SetBool("isWalking", false);
                anim.SetBool("weapon", false);
                anim.SetBool("isDead", true);
                Player.score++;
                if (!isDead)
                {
                    GameObject.Find("score").GetComponent<Text>().text = "Score : " + Player.score;
                }
                isDead = true;

                if (Application.loadedLevelName == "Jeu1")
                {
                    Application.LoadLevel("Jeu2");
                }
            }
        }
    }
開發者ID:KickAss42,項目名稱:Projet-SurvivAll,代碼行數:25,代碼來源:Mob.cs

示例4: OnCollisionEnter

    // Handle all collisions
    void OnCollisionEnter(Collision collision)
    {
        if (gameObject.name == "1_Player_East")
        {
            PlayerPrefs.SetInt("NumPlayers", 1);
            Application.LoadLevel(2);
        }
        if (gameObject.name == "1_Player_West")
        {
            PlayerPrefs.SetInt("NumPlayers", 1);
            Application.LoadLevel(3);
        }
        if (gameObject.name == "2_Player_East")
        {
            PlayerPrefs.SetInt("NumPlayers", 2);
            Application.LoadLevel(2);
        }
        if (gameObject.name == "2_Player_West")
        {
            PlayerPrefs.SetInt("NumPlayers", 2);
            Application.LoadLevel(3);
        }

        if (collision.gameObject.GetComponent(typeof(SnowBall)) != null )
        {
            if( (collision.gameObject.GetComponent(typeof(SnowBall)) as SnowBall).BallLauncher == SnowBall.Launcher.Enemy)
            {
                GUIManager.currentScore = GUIManager.currentScore - HitPenalty;
                if (PlayerPrefs.GetString("SelectedGameMode").Equals("HardMode"))
                {
                    GameController.lives--;
                }
            }
        }
    }
開發者ID:qimmer,項目名稱:mta13341,代碼行數:36,代碼來源:Player.cs

示例5: OnCollisionEnter

 void OnCollisionEnter(Collision collision)
 {
     if(collision.gameObject.tag == "BallTag")
     {
         GameOver(collision);
     }
 }
開發者ID:SebastiaanBuwalda,項目名稱:3DPinballUnity,代碼行數:7,代碼來源:DeathPit.cs

示例6: OnCollisionEnter

	public void OnCollisionEnter(Collision col)
	{
		if(col.gameObject.transform.position.x < transform.position.x)
			SendMessageUpwards("RotateDoorClock");//, col.gameObject.rigidbody.velocity.magnitude);
		else
			SendMessageUpwards("RotateDoorUnClock");
	}
開發者ID:jonwa,項目名稱:Project-Alix,代碼行數:7,代碼來源:Door.cs

示例7: OnCollisionEnter

 void OnCollisionEnter(Collision collision)
 {
     if(collision.gameObject.tag == "Bullet")
     {
         GetComponent<NavMeshAgent>().Warp(begin);
     }
 }
開發者ID:benjaml,項目名稱:PathfindingToolUnity,代碼行數:7,代碼來源:Poulpe2.cs

示例8: OnCollisionEnter

 void OnCollisionEnter(Collision collision)
 {
     //Debug.Log(collision.relativeVelocity.magnitude);
     if (collision.relativeVelocity.magnitude > 2){
         audio.Play();
     }
 }
開發者ID:Ghost---Shadow,項目名稱:UnityBowling,代碼行數:7,代碼來源:BowlingPin.cs

示例9: OnCollisionEnter

    void OnCollisionEnter(Collision col)
    {
        if(particule)
            GameObject.Instantiate(particule, transform.position, Quaternion.identity);

        //on inflige des degas au ennemis si il sont dans la zone
        EnemyController[] targets = FindObjectsOfType(System.Type.GetType("EnemyController")) as EnemyController[];
        for (int i=0; i<targets.Length; i++)
        {
            Vector3 distance = transform.position-targets[i].transform.position;
            if(distance.magnitude <= m_distance)
            {
                float damage = -m_damage + (-m_damage)/100 * targets[i].getSkillManager().getMagicResistance();
                //gestion de la furie
                if(m_furie)
                    damage += damage/100 * m_damageFurie;
                //gestion des critique
                if(m_factorCritique/100 < Random.value)
                    damage *= 2;
                targets[i].healthUpdate(damage);
            }
        }

        Destroy(this.gameObject);
    }
開發者ID:TheDeadMemoriesTeam,項目名稱:TheDeadMemories,代碼行數:25,代碼來源:SuperSkillController.cs

示例10: OnCollisionEnter

 void OnCollisionEnter(Collision col)
 {
     if (col.collider.CompareTag("Player") || col.collider.CompareTag("Item"))
     {
         isHurt = true;
     }
 }
開發者ID:doraoam,項目名稱:Pollo-Roller,代碼行數:7,代碼來源:HeadShot.cs

示例11: OnCollisionEnter

 void OnCollisionEnter(Collision c)
 {
     if (c.gameObject == GameObject.FindWithTag ("Boss"))
         SetPv (5);
     if (c.gameObject.tag == "fireennemy")
         SetPv (1);
 }
開發者ID:LMAdrien,項目名稱:SpaceInvader,代碼行數:7,代碼來源:PlayerMove.cs

示例12: OnCollisionEnter

 void OnCollisionEnter(Collision collision)
 {
     if(collision.collider.tag == "KillBox") {
         Destroy(gameObject);
         MultiManager.Instance.Board.DropHealth();
     }
 }
開發者ID:jrivera777,項目名稱:VoxelSlayer,代碼行數:7,代碼來源:Voxel.cs

示例13: OnCollisionEnter

    void OnCollisionEnter(Collision col)
    {
        if (!roadcols.Contains(col.collider.name))
        {

            if (col.collider.name.Equals("Road_Coll02_Side") && TriggerTimer.roundNo > rc2s)
            {
                Debug.Log("triggered");
                rc2s++;
            }
            else
            {

                if (col.collider.name.Equals("Road_Coll_Side") && RoadCollHelper.inTrigger)
                {
                    //do nothing
                }
                else
                {
                    Debug.Log(col.collider.name);
                    Debug.Log(col.relativeVelocity.magnitude);
                    velo.Add(col.relativeVelocity.magnitude);
                    TriggerTimer.collisions++;
                }
            }
        }
    }
開發者ID:Rickyfox,項目名稱:DSGG_new,代碼行數:27,代碼來源:CollisionHandler.cs

示例14: OnCollisionEnter

    void OnCollisionEnter(Collision other)
    {
        if (other.gameObject.layer == LayerMask.NameToLayer("TrackWall"))
        {
            // Get Collision impact
            float impact = Vector3.Dot(other.contacts[0].normal, other.relativeVelocity);
            float hitDot = Vector3.Dot(other.contacts[0].normal, transform.forward);

            if (Mathf.Abs(impact) > 1 && hitDot < 0.1f)
            {
                // Zero out relative Z velocity
                r.PlayOneShot(r.settings.SFX_WALLHIT);
                Vector3 lv = transform.InverseTransformDirection(r.body.velocity);
                lv.y = 0;
                lv.z = 0;
                Vector3 wv = transform.TransformDirection(lv);
                r.body.velocity = wv;

                // Reduce engine power and thrust
                enginePower *= 0.2f;
                engineThrust *= 0.2f;

                // Push ship away from wall
                Vector3 dir = other.contacts[0].normal;
                dir.y = 0;
                r.body.AddForce(dir * Mathf.Abs(impact), ForceMode.Impulse);

                // Spawn hit particle
                GameObject particle = Instantiate(Resources.Load("Particles/CollisionHit") as GameObject) as GameObject;
                particle.transform.position = other.contacts[0].point;
                particle.transform.forward = -transform.forward;

                // Ship take damage
                r.shield -= Mathf.Abs(impact * 2);

            }
        }

        if (other.gameObject.tag == "Ship")
        {

            //r.PlayOneShot(SHIP2SHIP SOUND);

            // Stop Bounce
            Vector3 lv = transform.InverseTransformDirection(r.body.velocity);
            lv.y = 0;
            Vector3 wv = transform.TransformDirection(lv);
            if (!isShipGrounded)
                r.body.velocity = wv;

            // Slow ship down slightly
            enginePower *= 0.8f;
            engineThrust *= 0.8f;

            // Push away from other ship
            Vector3 dir = other.contacts[0].normal;
            dir.y = 0;
            r.body.AddForce(dir * 4, ForceMode.Impulse);
        }
    }
開發者ID:dreadofmondays,項目名稱:BallisticNG,代碼行數:60,代碼來源:ShipSim.cs

示例15: OnCollisionEnter

 void OnCollisionEnter(Collision collision)
 {
     if (collision.collider.gameObject.tag.Equals("Player"))
     {
         collision.collider.rigidbody.AddForce(Vector3.forward * 100);
     }
 }
開發者ID:tedajax,項目名稱:puzzly,代碼行數:7,代碼來源:ClearDoorway.cs


注:本文中的Collision類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。