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


C# Collider.GetComponent方法代码示例

本文整理汇总了C#中Collider.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# Collider.GetComponent方法的具体用法?C# Collider.GetComponent怎么用?C# Collider.GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Collider的用法示例。


在下文中一共展示了Collider.GetComponent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Reflect

	public void Reflect(Collider coll, Vector3 reflDir)
	{
		if (coll.attachedRigidbody && coll.gameObject.layer == LayerMask.NameToLayer("Bullet"))
		{
			GameObject refl = Instantiate<GameObject>(bulletPrefab);
			refl.gameObject.tag = "SpawnedBullet";
			refl.transform.position = coll.transform.position;

			Vector3 vel;
			vel = reflDir;
			vel.Normalize();

			BulletBase reflBase = refl.GetComponent<BulletBase>();
			refl.GetComponent<Rigidbody>().velocity = vel * reflBase.bulletSpeed;

			reflBase.ignoreEnemies = false;
			reflBase.rend.material = reflBase.reflectMat;

			Destroy(coll.gameObject);
		}
		else if (coll.attachedRigidbody)
		{
			Vector3 vel;
			vel = reflDir * coll.GetComponent<Rigidbody>().velocity.magnitude;
			coll.GetComponent<Rigidbody>().velocity = vel;
		}
	}
开发者ID:nessenbu2,项目名称:EECS494,代码行数:27,代码来源:DefaultReflector.cs

示例2: OnTriggerEnter

    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Background") return;                                          // if it's Background return
        if (gameObject.tag == other.tag) return;                                        // if it's the same tag return

        if (destroyEffects.Length > 0)                                                        // if ther is some destroyeffects attached
        {
            int randIndex = Random.Range(0, destroyEffects.Length);                               // choose random index in array

            GameObject randEffect = destroyEffects[Random.Range(0, destroyEffects.Length)];
            GameObject newEffect = Instantiate(randEffect, transform.position, transform.rotation) as GameObject;
            newEffect.transform.SetParent(GameMaster.instance.hierarchyGuard);
        }
        else
            Debug.LogError("There is no destroy effect attached to " + gameObject.name);

        if (other.GetComponent<ObjectController>())            // if it exist
            other.GetComponent<ObjectController>().TakeDamage(damage);

        if (destroySounds.Length > 0)
        {
            SoundManager.instance.RandomizeSfx(ref destroySounds, ref audioSource);
            audioSource.Play();
        }
        else
            Debug.Log(other.name + " hasn't ObjectController script!");

        Destroy(gameObject);
    }
开发者ID:piotreczek5,项目名称:SpaceShooter,代码行数:29,代码来源:DestroyByCollision.cs

示例3: OnTriggerExit

    //reset drag on objects leaving water
    void OnTriggerExit(Collider other)
    {
        //rigidbody entered water?
        if(other.GetComponent<Rigidbody>())
        {
            Rigidbody r = other.GetComponent<Rigidbody>();
            //stop if we arent effecting player
            if(r.tag == "Player" && !effectPlayerDrag)
                return;

            //see if we've stored this objects default drag values
            if (dragStore.ContainsKey(r.gameObject) && angularStore.ContainsKey(r.gameObject))
            {
                //restore values
                r.drag = dragStore[r.gameObject];
                r.angularDrag = angularStore[r.gameObject];
                //remove stored values for this object
                dragStore.Remove(r.gameObject);
                angularStore.Remove (r.gameObject);
            }
            else
            {
                //restore default values incase we cant find it in list (for whatever reason)
                r.drag = 0f;
                r.angularDrag = 0.05f;
                print ("Object left water: couldn't get drag values, restored to defaults");
            }
        }
    }
开发者ID:ChromaTower,项目名称:ChromaProtoTower,代码行数:30,代码来源:Water.cs

示例4: OnTriggerEnter

    void OnTriggerEnter(Collider other)
    {
        switch (other.gameObject.name)
        {
            case "Knight":

                Knight knight = other.GetComponent<Knight>();
                knight.AdjustHealth(Damage);
                break;

            case "Caveman":

                Caveman caveman = other.GetComponent<Caveman>();
                caveman.AdjustHealth(Damage);
                break;

            case "Magician":

                Magician magician = other.GetComponent<Magician>();
                magician.AdjustHealth(Damage);
                break;

            case "Gunslinger":

                Gunslinger gunslinger = other.GetComponent<Gunslinger>();
                gunslinger.AdjustHealth(Damage);
                break;

        }

        Destroy(gameObject);
    }
开发者ID:PerrySpee,项目名称:aBITofMight,代码行数:32,代码来源:Fireball.cs

示例5: OnTriggerEnter

 void OnTriggerEnter(Collider other)
 {
     if (other.GetComponent<CharacterStats>())
     {
        // Debug.Log("1");
         if (other.GetComponent<CharacterStats>().Id != charStat.Id)
         {
         //    Debug.Log("2");
             if (!enAi.Enemies.Contains(other.gameObject))
             {
                 enAi.Enemies.Add(other.gameObject);
             }
         }
     }
     if (other.GetComponentInParent<CharacterStats>())
     {
        // Debug.Log("10");
         if (other.GetComponentInParent<CharacterStats>().Id != charStat.Id)
         {
         //    Debug.Log("20");
             if (!enAi.Enemies.Contains(other.GetComponentInParent<CharacterStats>().gameObject))
             {
                 enAi.Enemies.Add(other.GetComponentInParent<CharacterStats>().gameObject);
             }
         }
     }
 }
开发者ID:theawless,项目名称:Core-Attack,代码行数:27,代码来源:Sight.cs

示例6: OnTriggerEnter

    void OnTriggerEnter(Collider coll)
    {
        string tagString = coll.tag;
        if (tagString == "Player")
        {
            Rigidbody rig = coll.GetComponent<Rigidbody>();

            float jumpVel = Mathf.Sqrt(2 * Mathf.Abs(Physics.gravity.magnitude) * jumpHeight) + 0.25f;

            Vector3 vel = rig.velocity;
            vel.y = jumpVel;
            rig.velocity = vel;
        }
        else if (tagString == "Enemy")
        {
            Rigidbody rig = coll.GetComponent<Rigidbody>();

            float jumpVel = Mathf.Sqrt(2 * Mathf.Abs(Physics.gravity.magnitude) * jumpHeight) + 0.25f;

            Vector3 vel = rig.velocity;
            vel.y = jumpVel;
            rig.velocity = vel;

            coll.GetComponent<Attack_Enemy>().KickBoosted();
        }
    }
开发者ID:NWin95,项目名称:Bunches,代码行数:26,代码来源:JumpPad.cs

示例7: OnTriggerEnter

 //Diese Methode soll nur aufgerufen werden, wenn das Auto mit anderen Objecten Kollidiert,
 //Waffen werden von diesen Trigger nicht erkannt, da sie in einer anderen Layer liegen (layer-base collision detection)
 void OnTriggerEnter(Collider other)
 {
     if(car.GetComponent<Rigidbody>().velocity.magnitude > 10.0f
        && other.tag != "Checkpoint"
        && other.tag != "SpawnPoint"
        && other.GetComponent<ItemPickup>() == null){
         if(Network.connections.Length == 0){
             GameObject.Instantiate(virtualCrashPrefab,this.transform.position,this.transform.rotation);
         } else {
             Network.Instantiate(virtualCrashPrefab,this.transform.position,this.transform.rotation,0);
         }
     }
     //falls other ein DestructibleCarPart hat
     if(other.GetComponent<DestructibleCarPart>())
     {
         if(car.GetComponent<Rigidbody>().velocity.magnitude > 10.0f)
         {
             //schaden wird mit aktueller Geschwindigkeit multipliziert
             AbstractDestructibleObject destr = other.GetComponent<AbstractDestructibleObject>();
             if(destr != null)
             {
                 //relative Geschwindigkeit der beiden
                 Vector3 relVel = car.GetComponent<Rigidbody>().velocity - other.transform.root.GetComponent<Rigidbody>().velocity;
                 destr.receiveDamage(car.crashDamage * relVel.magnitude);
             }
         }
     }
 }
开发者ID:NoBudgetGames,项目名称:LastIgnition,代码行数:30,代码来源:CarCollision.cs

示例8: OnTriggerEnter

    void OnTriggerEnter(Collider other)
    {
        if(other.transform.CompareTag("Planet")){
            /* If the planet has been already destroyed do nothing. */
            if(((PlanetScript) other.GetComponent("PlanetScript")).isDestroyed())
                return;
            /* Set the status of the planet to 0 => Planet destroyed. */
            ((PlanetScript) other.GetComponent("PlanetScript")).setDestroyed();

            /* Update the score. */
            GameObject.Find("Controller").GetComponent<ControllerScript>().updateScore(-other.rigidbody.mass
                       * other.GetComponent<PlanetScript>().getPlanetPoints());
            foreach(GameObject star in GameObject.FindGameObjectsWithTag("Star")){
                    star.GetComponent<StarScript>().removeOrbitantPlanet(other.GetInstanceID());
                    star.GetComponent<StarScript>().updateMultiplier();
            }
            Debug.Log("Score:" + GameObject.Find("Controller").GetComponent<ControllerScript>().getScore());

            /* Get the Detonator script component */
            Detonator det = (Detonator) other.GetComponent("Detonator");
            /* Call Explode method defined in Detonator script. Simply show an explosion. */
            det.Explode();
            /* Play an explosion sound. */
            other.GetComponent<AudioSource>().Play();
            /*Adds the planet mass to the star mass*/
            rigidbody.mass += other.rigidbody.mass;
            /* Destroy the rigidboy of the collided planet. In this way it is no more subject to forces
               and has no speed. */
            Destroy(other.rigidbody);
            /* Hide the collided planet. */
            other.transform.position = transform.position;
            /* Destroy the game object of the planet. */
            Destroy(other.gameObject, 3);
        }
    }
开发者ID:Kariddi,项目名称:Revolution--The-game,代码行数:35,代码来源:StarScript.cs

示例9: OnTriggerEnter

 /// <summary>
 /// Raises the trigger enter event.
 /// </summary>
 /// <param name="col">Col.</param>
 void OnTriggerEnter(Collider col)
 {
     if (col.GetComponent<IKillable>() != null) {
         col.GetComponent<IKillable>().OnHit();
         DestroyObject (gameObject);
     }
 }
开发者ID:polenzdakota,项目名称:Pro-Game-Project,代码行数:11,代码来源:BulletScript.cs

示例10: OnTriggerEnter

 // ending stuff
 void OnTriggerEnter( Collider c )
 {
     if ( c.GetComponent<FirstPerson>() && !faded) {
         faded = true;
         StartCoroutine( WarpTimer( c.GetComponent<FirstPerson>() ) );
     }
 }
开发者ID:radiatoryang,项目名称:levelwithme2,代码行数:8,代码来源:EndFade.cs

示例11: OnTriggerEnter

 void OnTriggerEnter(Collider other)
 {
     if (other.tag == "Enemy") {
         other.GetComponent<NavMeshAgent> ().enabled = false;
         other.GetComponent<Rigidbody>().isKinematic = false;
     }
 }
开发者ID:DeSanguinist,项目名称:CobbleGame,代码行数:7,代码来源:KillNavmeshAgent.cs

示例12: OnTriggerEnter

    void OnTriggerEnter(Collider collider)
    {
        BaseVel = collider.gameObject.GetComponent<Rigidbody> ().velocity;

        //Camera.main.ScreenToWorldPoint (transform.position);

        //Camera.main.transform.Translate (transform.position, Space.World);

        //Camera.main.transform.position.x = transform.position.x;
        //Camera.main.transform.position.z = transform.position.z;

        var posVector = (transform.position - collider.transform.position);
        var angle = Vector3.Angle (posVector, collider.GetComponent<Rigidbody> ().velocity);

        Debug.Log ("angle val " + angle);

        Debug.Log (Vector3.Cross (posVector, collider.GetComponent<Rigidbody> ().velocity));

        if (Vector3.Cross (posVector, collider.GetComponent<Rigidbody> ().velocity).y > 0)
            collider.GetComponent<playerA> ().clockwise = false;
        else
            collider.GetComponent<playerA> ().clockwise = true;

        //		if (Mathf.Abs (angle) >= 45.0f) {
        //
        //			collider.GetComponent<playerA> ().canOrbit = true;
        //
        //
        //
        //			collider.GetComponent<Rigidbody> ().velocity = Vector3.zero;
        //
        //		}

        Debug.Log ("Player entered with an angle of " + angle + " " + " " +canOrbit);
    }
开发者ID:boracaliskanbas,项目名称:ReachKral,代码行数:35,代码来源:planetA.cs

示例13: OnTriggerEnter

 void OnTriggerEnter(Collider other)
 {
     if (other.GetComponent<PlayerMovement>() != null) {
         PlayerMovement player = other.GetComponent<PlayerMovement>();
         player.playerDamage = 100;
     }
 }
开发者ID:Daankovski,项目名称:AIM-3D,代码行数:7,代码来源:ArenaBoundaries.cs

示例14: OnTriggerStay

    void OnTriggerStay(Collider other)
    {
        if (other.gameObject.layer == enemyLayer && other.tag == "Enemy")
        {
            CellScript enemy = other.GetComponent<CellScript>();

            Vector3 enemyPos = enemy.GetCurrentLocation();

            Vector3 normalizedForceVector = (transform.position - enemyPos).normalized;

            enemy.SetGravitating(true);

            enemy.ApplyForce(normalizedForceVector * gravitationForce);
        }
        else if (other.gameObject.layer == enemyBulletLayer)
        {
            BulletScript bullet = other.GetComponent<BulletScript>();

            Vector3 bulletPos = bullet.transform.position;

            Vector3 normalizedForceVector = (transform.position - bulletPos).normalized;

            bullet.SetGravitating(true);

            bullet.ApplyForce(normalizedForceVector * gravitationForce);
        }
    }
开发者ID:Andrewnopoulos,项目名称:StrainAlpha,代码行数:27,代码来源:GravitationEffectScript.cs

示例15: ApplySwordDamage

 public void ApplySwordDamage(Collider other)
 {
     Debug.Log("dadsadsadsadadsdas");
     if (other.GetComponent<HealthSystem> () != null) {
         other.GetComponent<HealthSystem> ().ReceiveDamage (swordDamage);
     }
 }
开发者ID:Raysangar,项目名称:LudumDare33,代码行数:7,代码来源:SwordController.cs


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