本文整理汇总了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;
}
}
示例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);
}
示例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");
}
}
}
示例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);
}
示例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);
}
}
}
}
示例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();
}
}
示例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);
}
}
}
}
示例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);
}
}
示例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);
}
}
示例10: OnTriggerEnter
// ending stuff
void OnTriggerEnter( Collider c )
{
if ( c.GetComponent<FirstPerson>() && !faded) {
faded = true;
StartCoroutine( WarpTimer( c.GetComponent<FirstPerson>() ) );
}
}
示例11: OnTriggerEnter
void OnTriggerEnter(Collider other)
{
if (other.tag == "Enemy") {
other.GetComponent<NavMeshAgent> ().enabled = false;
other.GetComponent<Rigidbody>().isKinematic = false;
}
}
示例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);
}
示例13: OnTriggerEnter
void OnTriggerEnter(Collider other)
{
if (other.GetComponent<PlayerMovement>() != null) {
PlayerMovement player = other.GetComponent<PlayerMovement>();
player.playerDamage = 100;
}
}
示例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);
}
}
示例15: ApplySwordDamage
public void ApplySwordDamage(Collider other)
{
Debug.Log("dadsadsadsadadsdas");
if (other.GetComponent<HealthSystem> () != null) {
other.GetComponent<HealthSystem> ().ReceiveDamage (swordDamage);
}
}