本文整理汇总了C#中Collider.GetComponents方法的典型用法代码示例。如果您正苦于以下问题:C# Collider.GetComponents方法的具体用法?C# Collider.GetComponents怎么用?C# Collider.GetComponents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Collider
的用法示例。
在下文中一共展示了Collider.GetComponents方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnTriggerEnter
void OnTriggerEnter (Collider other){
if (other.gameObject.CompareTag("Bean"))
{
BonusEffects effects = other.gameObject.GetComponent<BonusEffects>();
BonusFactorCarrier bonus = other.gameObject.GetComponent<BonusFactorCarrier>();
if (effects != null)
{
if (HyperEffect)
{
bonus.addMultiplierB();
effects.HyperEffect.SetActive(true);
}
else
{
bonus.addMultiplierA();
effects.SuperEffect.SetActive(true);
}
AudioSource aus = other.GetComponents<AudioSource>()[0];
if (aus)
{
aus.Play();
}
}
}
}
示例2: OnTriggerEnter
void OnTriggerEnter(Collider other)
{
if(other.name == "Blobb")
{
controlScripts = other.GetComponents<Controls>();
player = other.transform.root.gameObject;
}
}
示例3: ApplyTo
/// <summary>
/// Apply damage to collider if it, or its rigidbody, has an IDamagable derived component.
/// </summary>
/// <param name="coll"></param>
/// <param name="amount"></param>
/// <param name="damageType"></param>
/// <param name="inflictor"></param>
public static void ApplyTo(Collider coll, int amount, DamageType damageType, GameObject inflictor)
{
IDamagable[] damagables = coll.GetComponents(typeof(IDamagable)).Cast<IDamagable>().ToArray();
DamageData dm = new DamageData(amount, damageType, inflictor);
Array.ForEach(damagables, damagable => damagable.TakeDamage(dm));
// Also apply damage to rigidbody of this collider, but only if they're different gameobjects (otherwise we already did)
if (coll.attachedRigidbody != null && coll.gameObject != coll.attachedRigidbody.gameObject)
{
IDamagable[] rigidBodyDamagables = coll.attachedRigidbody.GetComponents(typeof(IDamagable)).Cast<IDamagable>().ToArray();
Array.ForEach(rigidBodyDamagables, damagable => damagable.TakeDamage(dm));
}
}
示例4: OnTriggerEnter
private void OnTriggerEnter(Collider other)
{
MonoBehaviour[] components = other.GetComponents<MonoBehaviour>();
foreach (MonoBehaviour component in components)
{
ISplitable splitable = component as ISplitable;
if (splitable != null)
{
SplitObject(splitable, other.gameObject);
break;
}
}
}
示例5: OnTriggerExit
/// <summary>
/// Raises the trigger exit event.
/// </summary>
/// <param name="coll">Coll.</param>
void OnTriggerExit(Collider coll)
{
if (coll.gameObject.tag == "player" && coll.gameObject.GetComponent<PlayerStats> ().teamNumber == 1 && this.gameObject.name == "BeaconNorth") {
Collider[] allCols = coll.GetComponents<Collider> ();
HashSet<Collider> hashies = new HashSet<Collider> (allCols);
foreach (Collider col in hashies) {
if (col.isTrigger && col.GetType () == typeof(CapsuleCollider)) {
teamOneCaptureList.Remove (col);
Debug.Log ("" + teamOneCaptureList.Count);
}
}
}
if (coll.gameObject.tag == "player" && coll.gameObject.GetComponent<PlayerStats> ().teamNumber == 2 && this.gameObject.name == "BeaconNorth") {
Collider[] allCols = coll.GetComponents<Collider> ();
HashSet<Collider> hashies = new HashSet<Collider> (allCols);
foreach (Collider col in hashies) {
if (col.isTrigger && col.GetType () == typeof(CapsuleCollider)) {
teamTwoCaptureList.Remove (col);
Debug.Log ("" + teamTwoCaptureList.Count);
}
}
}
if (coll.gameObject.tag == "player" && coll.gameObject.GetComponent<PlayerStats> ().teamNumber == 1 && this.gameObject.name == "BeaconSouth") {
Collider[] allCols = coll.GetComponents<Collider> ();
HashSet<Collider> hashies = new HashSet<Collider> (allCols);
foreach (Collider col in hashies) {
if (col.isTrigger && col.GetType () == typeof(CapsuleCollider)) {
teamOneCaptureList.Remove (col);
Debug.Log ("" + teamOneCaptureList.Count);
}
}
}
if (coll.gameObject.tag == "player" && coll.gameObject.GetComponent<PlayerStats> ().teamNumber == 2 && this.gameObject.name == "BeaconSouth") {
Collider[] allCols = coll.GetComponents<Collider> ();
HashSet<Collider> hashies = new HashSet<Collider> (allCols);
foreach (Collider col in hashies) {
if (col.isTrigger && col.GetType () == typeof(CapsuleCollider)) {
teamTwoCaptureList.Remove (col);
Debug.Log ("" + teamTwoCaptureList.Count);
}
}
}
if (coll.gameObject.tag == "player" && coll.gameObject.GetComponent<PlayerStats> ().teamNumber == 1 && this.gameObject.name == "BeaconWest") {
Collider[] allCols = coll.GetComponents<Collider> ();
HashSet<Collider> hashies = new HashSet<Collider> (allCols);
foreach (Collider col in hashies) {
if (col.isTrigger && col.GetType () == typeof(CapsuleCollider)) {
teamOneCaptureList.Remove (col);
Debug.Log ("" + teamOneCaptureList.Count);
}
}
}
if (coll.gameObject.tag == "player" && coll.gameObject.GetComponent<PlayerStats> ().teamNumber == 2 && this.gameObject.name == "BeaconWest") {
Collider[] allCols = coll.GetComponents<Collider> ();
HashSet<Collider> hashies = new HashSet<Collider> (allCols);
foreach (Collider col in hashies) {
if (col.isTrigger && col.GetType () == typeof(CapsuleCollider)) {
teamTwoCaptureList.Remove (col);
Debug.Log ("" + teamTwoCaptureList.Count);
}
}
}
if (coll.gameObject.tag == "player" && coll.gameObject.GetComponent<PlayerStats> ().teamNumber == 1 && this.gameObject.name == "BeaconEast") {
Collider[] allCols = coll.GetComponents<Collider> ();
HashSet<Collider> hashies = new HashSet<Collider> (allCols);
foreach (Collider col in hashies) {
if (col.isTrigger && col.GetType () == typeof(CapsuleCollider)) {
teamOneCaptureList.Remove (col);
Debug.Log ("" + teamOneCaptureList.Count);
}
}
}
if (coll.gameObject.tag == "player" && coll.gameObject.GetComponent<PlayerStats> ().teamNumber == 2 && this.gameObject.name == "BeaconEast") {
Collider[] allCols = coll.GetComponents<Collider> ();
HashSet<Collider> hashies = new HashSet<Collider> (allCols);
foreach (Collider col in hashies) {
if (col.isTrigger && col.GetType () == typeof(CapsuleCollider)) {
teamTwoCaptureList.Remove (col);
Debug.Log ("" + teamTwoCaptureList.Count);
}
}
}
}
示例6: OnTriggerStay
void OnTriggerStay(Collider other)
{
if (grabbedObject != null)
{
return;
}
// hitListに何か含まれていればreturn。(拾えるもの優先)
foreach (GraspItem listItem in hitList)
{
ColorObjectBase colorObject = listItem.GetComponent<ColorObjectBase>();
if (colorObject != null)
{
if (!colorObject.isDisappearance)
{
return;
}
}
else
{
return;
}
}
// 目の前の物を調べる
// 調べられるもの全てを配列として取得
Component[] checkComponents = other.GetComponents(typeof(ICheckEvent));
if (checkComponents == null)
{
return;
}
ExamineIconManager.HideIcon();
if ((Input.GetKeyDown(KeyCode.E) || Input.GetMouseButtonDown(1)) && !player.isIrradiation)
{
foreach (ICheckEvent component in checkComponents)
{
component.Check();
}
}
}