Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

How do I assign an object to another collider?

Discussion in 'Physics' started by leon100906, Feb 7, 2021.

  1. leon100906

    leon100906

    Joined:
    Nov 25, 2019
    Posts:
    2
    Hello, I was making a realistic tornado damage, but I wanted to have multiple trigger zone for each other object. I was making one, but I kept getting errors. Can you please help me out? Thanks!

    Also, here is the script:


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class NewDamage : MonoBehaviour
    6. {
    7.     [Tooltip("The Triggerzone of EF0 Damage")]
    8.     public Collider EF0;
    9.  
    10.     [Tooltip("The Triggerzone of EF1 Damage")]
    11.     public Collider EF1;
    12.  
    13.     [Tooltip("The Triggerzone of EF2 Damage")]
    14.     public Collider EF2;
    15.  
    16.     [Tooltip("The Triggerzone of EF3 Damage")]
    17.     public Collider EF3;
    18.  
    19.     [Tooltip("The Triggerzone of EF4 Damage")]
    20.     public Collider EF4;
    21.  
    22.     [Tooltip("The Triggerzone of EF5 Damage")]
    23.     public Collider EF5;
    24.  
    25.     [Tooltip("The Triggerzone of EF6 Damage")]
    26.     public Collider EF6;
    27.  
    28.     [Tooltip("The Triggerzone of F7 Damage")]
    29.     public Collider F7;
    30.  
    31.     [Tooltip("The Triggerzone of F8 Damage")]
    32.     public Collider F8;
    33.  
    34.     [Tooltip("The Glass Breaking Sound")]
    35.     public GameObject GB;
    36.  
    37.     [Tooltip("The Structure Breaking Sound")]
    38.     public GameObject SB;
    39.  
    40.     [Tooltip("Prevents the excessive use of sounds")]
    41.     public float debounce;
    42.  
    43.     [Tooltip("The Current EF Scale")]
    44.     public float EF;
    45.  
    46.     [Tooltip("Distance after which the rotation physics starts")]
    47.     public float maxDistance = 20;
    48.  
    49.     [Tooltip("The axis that the caught objects will rotate around")]
    50.     public Vector3 rotationAxis = new Vector3(0, 1, 0);
    51.  
    52.     [Tooltip("Angle that is added to the object's velocity (higher lift -> quicker on top)")]
    53.     [Range(0, 90)]
    54.     public float lift = 45;
    55.  
    56.     [Tooltip("The force that will drive the caught objects around the tornado's center")]
    57.     public float rotationStrength = 50;
    58.  
    59.     [Tooltip("Tornado pull force")]
    60.     public float tornadoStrength = 2;
    61.  
    62.     Rigidbody r;
    63.  
    64.     List<SC_Caught> caughtObject = new List<SC_Caught>();
    65.  
    66.     // Start is called before the first frame update
    67.     void Start()
    68.     {
    69.         //Normalize the rotation axis given by the user
    70.         rotationAxis.Normalize();
    71.  
    72.         r = GetComponent<Rigidbody>();
    73.         r.isKinematic = true;
    74.     }
    75.  
    76.     void FixedUpdate()
    77.     {
    78.         //Apply force to caught objects
    79.         for (int i = 0; i < caughtObject.Count; i++)
    80.         {
    81.             if (caughtObject != null)
    82.             {
    83.                 Vector3 pull = transform.position - caughtObject.transform.position;
    84.                 if (pull.magnitude > maxDistance)
    85.                 {
    86.                     caughtObject.rigid.AddForce(pull.normalized * pull.magnitude, ForceMode.Force);
    87.                     caughtObject.enabled = false;
    88.                 }
    89.                 else
    90.                 {
    91.                     caughtObject.enabled = true;
    92.                 }
    93.             }
    94.         }
    95.     }
    96.  
    97.     void OnTriggerEnter(Collider other)
    98.     {
    99.         if (!other.attachedRigidbody) return;
    100.      
    101.  
    102.  
    103.         //Add caught object to the list
    104.         if ((EF == 0))
    105.         {
    106.             if (other.tag == "F0")
    107.             {
    108.                 GameObject AAAA2 = Instantiate(SB, other.transform.position, Quaternion.identity) as GameObject;
    109.                 AAAA2.GetComponent<Structurebreak_sound_controller>().debounce = Random.Range(0, 10);
    110.                 other.gameObject.GetComponent<Rigidbody>().isKinematic = false;
    111.                 SC_Caught caught = other.GetComponent<SC_Caught>();
    112.                 if (!caught)
    113.                 {
    114.                     caught = other.gameObject.AddComponent<SC_Caught>();
    115.  
    116.                 }
    117.  
    118.                 caught.Init(this, r, tornadoStrength);
    119.  
    120.                 if (!caughtObject.Contains(caught))
    121.                 {
    122.                     caughtObject.Add(caught);
    123.                 }
    124.             }
    125.         }
    126.         if ((EF == 1))
    127.         {
    128.             if (other.tag == "F0" || other.tag == "F1")
    129.             {
    130.                 GameObject AAAA2 = Instantiate(SB, other.transform.position, Quaternion.identity) as GameObject;
    131.                 AAAA2.GetComponent<Structurebreak_sound_controller>().debounce = Random.Range(0, 10);
    132.                 other.gameObject.GetComponent<Rigidbody>().isKinematic = false;
    133.                 SC_Caught caught = other.GetComponent<SC_Caught>();
    134.                 if (!caught)
    135.                 {
    136.                     caught = other.gameObject.AddComponent<SC_Caught>();
    137.                 }
    138.  
    139.                 caught.Init(this, r, tornadoStrength);
    140.  
    141.                 if (!caughtObject.Contains(caught))
    142.                 {
    143.                     caughtObject.Add(caught);
    144.                 }
    145.             }
    146.  
    147.             if (other.tag == "Glass")
    148.             {
    149.                 Destroy(other.gameObject);
    150.                 GameObject AAAA = Instantiate(GB, other.transform.position, Quaternion.identity) as GameObject;
    151.             }
    152.         }
    153.         if ((EF == 2))
    154.         {
    155.             if (other.tag == "F0" || other.tag == "F1" || other.tag == "F2")
    156.             {
    157.                 GameObject AAAA2 = Instantiate(SB, other.transform.position, Quaternion.identity) as GameObject;
    158.                 AAAA2.GetComponent<Structurebreak_sound_controller>().debounce = Random.Range(0, 10);
    159.                 other.gameObject.GetComponent<Rigidbody>().isKinematic = false;
    160.                 SC_Caught caught = other.GetComponent<SC_Caught>();
    161.                 if (!caught)
    162.                 {
    163.                     caught = other.gameObject.AddComponent<SC_Caught>();
    164.                 }
    165.  
    166.                 caught.Init(this, r, tornadoStrength);
    167.  
    168.                 if (!caughtObject.Contains(caught))
    169.                 {
    170.                     caughtObject.Add(caught);
    171.                 }
    172.             }
    173.  
    174.             if (other.tag == "Glass")
    175.             {
    176.                 Destroy(other.gameObject);
    177.                 GameObject AAAA = Instantiate(GB, other.transform.position, Quaternion.identity) as GameObject;
    178.             }
    179.         }
    180.         if ((EF == 3))
    181.         {
    182.             if (other.tag == "F0" || other.tag == "F1" || other.tag == "F2" || other.tag == "F3")
    183.             {
    184.                 GameObject AAAA2 = Instantiate(SB, other.transform.position, Quaternion.identity) as GameObject;
    185.                 AAAA2.GetComponent<Structurebreak_sound_controller>().debounce = Random.Range(0, 10);
    186.                 other.gameObject.GetComponent<Rigidbody>().isKinematic = false;
    187.                 SC_Caught caught = other.GetComponent<SC_Caught>();
    188.                 if (!caught)
    189.                 {
    190.                     caught = other.gameObject.AddComponent<SC_Caught>();
    191.                 }
    192.  
    193.                 caught.Init(this, r, tornadoStrength);
    194.  
    195.                 if (!caughtObject.Contains(caught))
    196.                 {
    197.                     caughtObject.Add(caught);
    198.                 }
    199.             }
    200.  
    201.             if (other.tag == "Glass")
    202.             {
    203.                 Destroy(other.gameObject);
    204.                 GameObject AAAA = Instantiate(GB, other.transform.position, Quaternion.identity) as GameObject;
    205.             }
    206.         }
    207.         if ((EF == 4))
    208.         {
    209.             if (other.tag == "F0" || other.tag == "F1" || other.tag == "F2" || other.tag == "F3" || other.tag == "F4")
    210.             {
    211.                 GameObject AAAA2 = Instantiate(SB, other.transform.position, Quaternion.identity) as GameObject;
    212.                 AAAA2.GetComponent<Structurebreak_sound_controller>().debounce = Random.Range(0, 10);
    213.                 other.gameObject.GetComponent<Rigidbody>().isKinematic = false;
    214.                 SC_Caught caught = other.GetComponent<SC_Caught>();
    215.                 if (!caught)
    216.                 {
    217.                     caught = other.gameObject.AddComponent<SC_Caught>();
    218.                 }
    219.  
    220.                 caught.Init(this, r, tornadoStrength);
    221.  
    222.                 if (!caughtObject.Contains(caught))
    223.                 {
    224.                     caughtObject.Add(caught);
    225.                 }
    226.             }
    227.  
    228.             if (other.tag == "Glass")
    229.             {
    230.                 Destroy(other.gameObject);
    231.                 GameObject AAAA = Instantiate(GB, other.transform.position, Quaternion.identity) as GameObject;
    232.             }
    233.         }
    234.         if ((EF == 5))
    235.         {
    236.             if (other.tag == "F0" || other.tag == "F1" || other.tag == "F2" || other.tag == "F3" || other.tag == "F4" || other.tag == "F5")
    237.             {
    238.                 GameObject AAAA2 = Instantiate(SB, other.transform.position, Quaternion.identity) as GameObject;
    239.                 AAAA2.GetComponent<Structurebreak_sound_controller>().debounce = Random.Range(0, 10);
    240.                 other.gameObject.GetComponent<Rigidbody>().isKinematic = false;
    241.                 SC_Caught caught = other.GetComponent<SC_Caught>();
    242.                 if (!caught)
    243.                 {
    244.                     caught = other.gameObject.AddComponent<SC_Caught>();
    245.                 }
    246.  
    247.                 caught.Init(this, r, tornadoStrength);
    248.  
    249.                 if (!caughtObject.Contains(caught))
    250.                 {
    251.                     caughtObject.Add(caught);
    252.                 }
    253.             }
    254.  
    255.             if (other.tag == "Glass")
    256.             {
    257.                 Destroy(other.gameObject);
    258.                 GameObject AAAA = Instantiate(GB, other.transform.position, Quaternion.identity) as GameObject;
    259.             }
    260.         }
    261.         if ((EF == 6))
    262.         {
    263.             if (other.tag == "F0" || other.tag == "F1" || other.tag == "F2" || other.tag == "F3" || other.tag == "F4" || other.tag == "F5" || other.tag == "F6")
    264.             {
    265.                 GameObject AAAA2 = Instantiate(SB, other.transform.position, Quaternion.identity) as GameObject;
    266.                 AAAA2.GetComponent<Structurebreak_sound_controller>().debounce = Random.Range(0, 10);
    267.                 other.gameObject.GetComponent<Rigidbody>().isKinematic = false;
    268.                 SC_Caught caught = other.GetComponent<SC_Caught>();
    269.                 if (!caught)
    270.                 {
    271.                     caught = other.gameObject.AddComponent<SC_Caught>();
    272.                 }
    273.  
    274.                 caught.Init(this, r, tornadoStrength);
    275.  
    276.                 if (!caughtObject.Contains(caught))
    277.                 {
    278.                     caughtObject.Add(caught);
    279.                 }
    280.             }
    281.  
    282.             if (other.tag == "Glass")
    283.             {
    284.                 Destroy(other.gameObject);
    285.                 GameObject AAAA = Instantiate(GB, other.transform.position, Quaternion.identity) as GameObject;
    286.             }
    287.         }
    288.         if ((EF == 7))
    289.         {
    290.             if (other.tag == "F0" || other.tag == "F1" || other.tag == "F2" || other.tag == "F3" || other.tag == "F4" || other.tag == "F5" || other.tag == "F6" || other.tag == "F7")
    291.             {
    292.                 GameObject AAAA2 = Instantiate(SB, other.transform.position, Quaternion.identity) as GameObject;
    293.                 AAAA2.GetComponent<Structurebreak_sound_controller>().debounce = Random.Range(0, 10);
    294.                 other.gameObject.GetComponent<Rigidbody>().isKinematic = false;
    295.                 SC_Caught caught = other.GetComponent<SC_Caught>();
    296.                 if (!caught)
    297.                 {
    298.                     caught = other.gameObject.AddComponent<SC_Caught>();
    299.                 }
    300.  
    301.                 caught.Init(this, r, tornadoStrength);
    302.  
    303.                 if (!caughtObject.Contains(caught))
    304.                 {
    305.                     caughtObject.Add(caught);
    306.                 }
    307.             }
    308.  
    309.             if (other.tag == "Glass")
    310.             {
    311.                 Destroy(other.gameObject);
    312.                 GameObject AAAA = Instantiate(GB, other.transform.position, Quaternion.identity) as GameObject;
    313.             }
    314.         }
    315.         if ((EF == 8))
    316.         {
    317.             if (other.tag == "F0" || other.tag == "F1" || other.tag == "F2" || other.tag == "F3" || other.tag == "F4" || other.tag == "F5" || other.tag == "F6" || other.tag == "F7" || other.tag == "F8")
    318.             {
    319.                 GameObject AAAA2 = Instantiate(SB, other.transform.position, Quaternion.identity) as GameObject;
    320.                 AAAA2.GetComponent<Structurebreak_sound_controller>().debounce = Random.Range(0, 10);
    321.                 other.gameObject.GetComponent<Rigidbody>().isKinematic = false;
    322.                 SC_Caught caught = other.GetComponent<SC_Caught>();
    323.                 if (!caught)
    324.                 {
    325.                     caught = other.gameObject.AddComponent<SC_Caught>();
    326.                 }
    327.  
    328.                 caught.Init(this, r, tornadoStrength);
    329.  
    330.                 if (!caughtObject.Contains(caught))
    331.                 {
    332.                     caughtObject.Add(caught);
    333.                 }
    334.             }
    335.  
    336.             if (other.tag == "Glass")
    337.             {
    338.                 Destroy(other.gameObject);
    339.                 GameObject AAAA = Instantiate(GB, other.transform.position, Quaternion.identity) as GameObject;
    340.             }
    341.         }
    342.     }
    343.  
    344.     void OnTriggerExit(Collider other)
    345.     {
    346.         //Release caught object
    347.         SC_Caught caught = other.GetComponent<SC_Caught>();
    348.         if (caught)
    349.         {
    350.             caught.Release();
    351.  
    352.             if (caughtObject.Contains(caught))
    353.             {
    354.                 caughtObject.Remove(caught);
    355.             }
    356.         }
    357.     }
    358.  
    359.     public float GetStrength()
    360.     {
    361.         return rotationStrength;
    362.     }
    363.  
    364.     //The axis the caught objects rotate around
    365.     public Vector3 GetRotationAxis()
    366.     {
    367.         return rotationAxis;
    368.     }
    369.  
    370.     //Draw tornado radius circle in Editor
    371.     void OnDrawGizmosSelected()
    372.     {
    373.         Vector3[] positions = new Vector3[30];
    374.         Vector3 centrePos = transform.position;
    375.         for (int pointNum = 0; pointNum < positions.Length; pointNum++)
    376.         {
    377.             // "i" now represents the progress around the circle from 0-1
    378.             // we multiply by 1.0 to ensure we get a fraction as a result.
    379.             float i = (float)(pointNum * 2) / positions.Length;
    380.  
    381.             // get the angle for this step (in radians, not degrees)
    382.             float angle = i * Mathf.PI * 2;
    383.  
    384.             // the X & Y position for this angle are calculated using Sin & Cos
    385.             float x = Mathf.Sin(angle) * maxDistance;
    386.             float z = Mathf.Cos(angle) * maxDistance;
    387.  
    388.             Vector3 pos = new Vector3(x, 0, z) + centrePos;
    389.             positions[pointNum] = pos;
    390.         }
    391.  
    392.         Gizmos.color = Color.cyan;
    393.         for (int i = 0; i < positions.Length; i++)
    394.         {
    395.             if (i == positions.Length - 1)
    396.             {
    397.                 Gizmos.DrawLine(positions[0], positions[positions.Length - 1]);
    398.             }
    399.             else
    400.             {
    401.                 Gizmos.DrawLine(positions, positions[i + 1]);
    402.             }
    403.         }
    404.     }
    405.  
    406. }
     
    Last edited: Feb 7, 2021
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,546
    Please don't post walls of plain text as you must see that it's unreadable; please use code tags.

    Also, this looks like a general scripting issue even though you're dealing with colliders. You say you get errors but don't state what they are. If you want help, please spend some time producing a post where devs can help you, explaining what you've tried and expect, what goes wrong including errors and the lines they occur on etc. That way you'll get a quicker response rather than lots of back/forth asking questions or even ignored as it takes a lot of effort to help.
     
  3. leon100906

    leon100906

    Joined:
    Nov 25, 2019
    Posts:
    2
    Ok, here's an update, I'm getting errors about ontrigger enter that it must have 0 or 1 parameters, how do I fix this? here is the script:


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class NewDamage : MonoBehaviour
    6. {
    7.  
    8.     public Collider EF0;
    9.     public Collider EF1;
    10.  
    11.     [Tooltip("The Glass Breaking Sound")]
    12.     public GameObject GB;
    13.  
    14.     [Tooltip("The Structure Breaking Sound")]
    15.     public GameObject SB;
    16.  
    17.     [Tooltip("Prevents the excessive use of sounds")]
    18.     public float debounce;
    19.  
    20.     [Tooltip("The Current EF Scale")]
    21.     public float EF;
    22.  
    23.     [Tooltip("Distance after which the rotation physics starts")]
    24.     public float maxDistance = 20;
    25.  
    26.     [Tooltip("The axis that the caught objects will rotate around")]
    27.     public Vector3 rotationAxis = new Vector3(0, 1, 0);
    28.  
    29.     [Tooltip("Angle that is added to the object's velocity (higher lift -> quicker on top)")]
    30.     [Range(0, 90)]
    31.     public float lift = 45;
    32.  
    33.     [Tooltip("The force that will drive the caught objects around the tornado's center")]
    34.     public float rotationStrength = 50;
    35.  
    36.     [Tooltip("Tornado pull force")]
    37.     public float tornadoStrength = 2;
    38.  
    39.     Rigidbody r;
    40.  
    41.     List<SC_Caught> caughtObject = new List<SC_Caught>();
    42.  
    43.     // Start is called before the first frame update
    44.     void Start()
    45.     {
    46.         //Normalize the rotation axis given by the user
    47.         rotationAxis.Normalize();
    48.  
    49.         r = GetComponent<Rigidbody>();
    50.         r.isKinematic = true;
    51.     }
    52.  
    53.     void FixedUpdate()
    54.     {
    55.         //Apply force to caught objects
    56.         for (int i = 0; i < caughtObject.Count; i++)
    57.         {
    58.             if (caughtObject[i] != null)
    59.             {
    60.                 Vector3 pull = transform.position - caughtObject[i].transform.position;
    61.                 if (pull.magnitude > maxDistance)
    62.                 {
    63.                     caughtObject[i].rigid.AddForce(pull.normalized * pull.magnitude, ForceMode.Force);
    64.                     caughtObject[i].enabled = false;
    65.                 }
    66.                 else
    67.                 {
    68.                     caughtObject[i].enabled = true;
    69.                 }
    70.             }
    71.         }
    72.     }
    73.  
    74.     void OnTriggerEnter(Collider other,Collider other1) //The error is caused by here
    75.     {
    76.         if (!other.attachedRigidbody) return;
    77.         if (!other1.attachedRigidbody) return;
    78.  
    79.         EF0 = other;
    80.         EF1 = other1;
    81.  
    82.         //Add caught object to the list
    83.         if ((EF == 0))
    84.         {
    85.             if (other.tag == "F0")
    86.             {  
    87.  
    88.  
    89.                 GameObject AAAA2 = Instantiate(SB, other.transform.position, Quaternion.identity) as GameObject;
    90.                 AAAA2.GetComponent<Structurebreak_sound_controller>().debounce = Random.Range(0, 10);
    91.                 other.gameObject.GetComponent<Rigidbody>().isKinematic = false;
    92.                 SC_Caught caught = other.GetComponent<SC_Caught>();
    93.                 if (!caught)
    94.                 {
    95.                     caught = other.gameObject.AddComponent<SC_Caught>();
    96.  
    97.                 }
    98.  
    99.                 caught.Init(this, r, tornadoStrength);
    100.  
    101.                 if (!caughtObject.Contains(caught))
    102.                 {
    103.                     caughtObject.Add(caught);
    104.                 }
    105.             }
    106.         }
    107.         if ((EF == 1))
    108.         {
    109.             if (other.tag == "F0" || other.tag == "F1")
    110.             {
    111.                 GameObject AAAA2 = Instantiate(SB, other.transform.position, Quaternion.identity) as GameObject;
    112.                 AAAA2.GetComponent<Structurebreak_sound_controller>().debounce = Random.Range(0, 10);
    113.                 other.gameObject.GetComponent<Rigidbody>().isKinematic = false;
    114.                 SC_Caught caught = other.GetComponent<SC_Caught>();
    115.                 if (!caught)
    116.                 {
    117.                     caught = other.gameObject.AddComponent<SC_Caught>();
    118.                 }
    119.  
    120.                 caught.Init(this, r, tornadoStrength);
    121.  
    122.                 if (!caughtObject.Contains(caught))
    123.                 {
    124.                     caughtObject.Add(caught);
    125.                 }
    126.             }
    127.  
    128.             if (other.tag == "Glass")
    129.             {
    130.                 Destroy(other.gameObject);
    131.                 GameObject AAAA = Instantiate(GB, other.transform.position, Quaternion.identity) as GameObject;
    132.             }
    133.         }
    134.         if ((EF == 2))
    135.         {
    136.             if (other.tag == "F0" || other.tag == "F1" || other.tag == "F2")
    137.             {
    138.                 GameObject AAAA2 = Instantiate(SB, other.transform.position, Quaternion.identity) as GameObject;
    139.                 AAAA2.GetComponent<Structurebreak_sound_controller>().debounce = Random.Range(0, 10);
    140.                 other.gameObject.GetComponent<Rigidbody>().isKinematic = false;
    141.                 SC_Caught caught = other.GetComponent<SC_Caught>();
    142.                 if (!caught)
    143.                 {
    144.                     caught = other.gameObject.AddComponent<SC_Caught>();
    145.                 }
    146.  
    147.                 caught.Init(this, r, tornadoStrength);
    148.  
    149.                 if (!caughtObject.Contains(caught))
    150.                 {
    151.                     caughtObject.Add(caught);
    152.                 }
    153.             }
    154.  
    155.             if (other.tag == "Glass")
    156.             {
    157.                 Destroy(other.gameObject);
    158.                 GameObject AAAA = Instantiate(GB, other.transform.position, Quaternion.identity) as GameObject;
    159.             }
    160.         }
    161.         if ((EF == 3))
    162.         {
    163.             if (other.tag == "F0" || other.tag == "F1" || other.tag == "F2" || other.tag == "F3")
    164.             {
    165.                 GameObject AAAA2 = Instantiate(SB, other.transform.position, Quaternion.identity) as GameObject;
    166.                 AAAA2.GetComponent<Structurebreak_sound_controller>().debounce = Random.Range(0, 10);
    167.                 other.gameObject.GetComponent<Rigidbody>().isKinematic = false;
    168.                 SC_Caught caught = other.GetComponent<SC_Caught>();
    169.                 if (!caught)
    170.                 {
    171.                     caught = other.gameObject.AddComponent<SC_Caught>();
    172.                 }
    173.  
    174.                 caught.Init(this, r, tornadoStrength);
    175.  
    176.                 if (!caughtObject.Contains(caught))
    177.                 {
    178.                     caughtObject.Add(caught);
    179.                 }
    180.             }
    181.  
    182.             if (other.tag == "Glass")
    183.             {
    184.                 Destroy(other.gameObject);
    185.                 GameObject AAAA = Instantiate(GB, other.transform.position, Quaternion.identity) as GameObject;
    186.             }
    187.         }
    188.         if ((EF == 4))
    189.         {
    190.             if (other.tag == "F0" || other.tag == "F1" || other.tag == "F2" || other.tag == "F3" || other.tag == "F4")
    191.             {
    192.                 GameObject AAAA2 = Instantiate(SB, other.transform.position, Quaternion.identity) as GameObject;
    193.                 AAAA2.GetComponent<Structurebreak_sound_controller>().debounce = Random.Range(0, 10);
    194.                 other.gameObject.GetComponent<Rigidbody>().isKinematic = false;
    195.                 SC_Caught caught = other.GetComponent<SC_Caught>();
    196.                 if (!caught)
    197.                 {
    198.                     caught = other.gameObject.AddComponent<SC_Caught>();
    199.                 }
    200.  
    201.                 caught.Init(this, r, tornadoStrength);
    202.  
    203.                 if (!caughtObject.Contains(caught))
    204.                 {
    205.                     caughtObject.Add(caught);
    206.                 }
    207.             }
    208.  
    209.             if (other.tag == "Glass")
    210.             {
    211.                 Destroy(other.gameObject);
    212.                 GameObject AAAA = Instantiate(GB, other.transform.position, Quaternion.identity) as GameObject;
    213.             }
    214.         }
    215.         if ((EF == 5))
    216.         {
    217.             if (other.tag == "F0" || other.tag == "F1" || other.tag == "F2" || other.tag == "F3" || other.tag == "F4" || other.tag == "F5")
    218.             {
    219.                 GameObject AAAA2 = Instantiate(SB, other.transform.position, Quaternion.identity) as GameObject;
    220.                 AAAA2.GetComponent<Structurebreak_sound_controller>().debounce = Random.Range(0, 10);
    221.                 other.gameObject.GetComponent<Rigidbody>().isKinematic = false;
    222.                 SC_Caught caught = other.GetComponent<SC_Caught>();
    223.                 if (!caught)
    224.                 {
    225.                     caught = other.gameObject.AddComponent<SC_Caught>();
    226.                 }
    227.  
    228.                 caught.Init(this, r, tornadoStrength);
    229.  
    230.                 if (!caughtObject.Contains(caught))
    231.                 {
    232.                     caughtObject.Add(caught);
    233.                 }
    234.             }
    235.  
    236.             if (other.tag == "Glass")
    237.             {
    238.                 Destroy(other.gameObject);
    239.                 GameObject AAAA = Instantiate(GB, other.transform.position, Quaternion.identity) as GameObject;
    240.             }
    241.         }
    242.         if ((EF == 6))
    243.         {
    244.             if (other.tag == "F0" || other.tag == "F1" || other.tag == "F2" || other.tag == "F3" || other.tag == "F4" || other.tag == "F5" || other.tag == "F6")
    245.             {
    246.                 GameObject AAAA2 = Instantiate(SB, other.transform.position, Quaternion.identity) as GameObject;
    247.                 AAAA2.GetComponent<Structurebreak_sound_controller>().debounce = Random.Range(0, 10);
    248.                 other.gameObject.GetComponent<Rigidbody>().isKinematic = false;
    249.                 SC_Caught caught = other.GetComponent<SC_Caught>();
    250.                 if (!caught)
    251.                 {
    252.                     caught = other.gameObject.AddComponent<SC_Caught>();
    253.                 }
    254.  
    255.                 caught.Init(this, r, tornadoStrength);
    256.  
    257.                 if (!caughtObject.Contains(caught))
    258.                 {
    259.                     caughtObject.Add(caught);
    260.                 }
    261.             }
    262.  
    263.             if (other.tag == "Glass")
    264.             {
    265.                 Destroy(other.gameObject);
    266.                 GameObject AAAA = Instantiate(GB, other.transform.position, Quaternion.identity) as GameObject;
    267.             }
    268.         }
    269.         if ((EF == 7))
    270.         {
    271.             if (other.tag == "F0" || other.tag == "F1" || other.tag == "F2" || other.tag == "F3" || other.tag == "F4" || other.tag == "F5" || other.tag == "F6" || other.tag == "F7")
    272.             {
    273.                 GameObject AAAA2 = Instantiate(SB, other.transform.position, Quaternion.identity) as GameObject;
    274.                 AAAA2.GetComponent<Structurebreak_sound_controller>().debounce = Random.Range(0, 10);
    275.                 other.gameObject.GetComponent<Rigidbody>().isKinematic = false;
    276.                 SC_Caught caught = other.GetComponent<SC_Caught>();
    277.                 if (!caught)
    278.                 {
    279.                     caught = other.gameObject.AddComponent<SC_Caught>();
    280.                 }
    281.  
    282.                 caught.Init(this, r, tornadoStrength);
    283.  
    284.                 if (!caughtObject.Contains(caught))
    285.                 {
    286.                     caughtObject.Add(caught);
    287.                 }
    288.             }
    289.  
    290.             if (other.tag == "Glass")
    291.             {
    292.                 Destroy(other.gameObject);
    293.                 GameObject AAAA = Instantiate(GB, other.transform.position, Quaternion.identity) as GameObject;
    294.             }
    295.         }
    296.         if ((EF == 8))
    297.         {
    298.             if (other.tag == "F0" || other.tag == "F1" || other.tag == "F2" || other.tag == "F3" || other.tag == "F4" || other.tag == "F5" || other.tag == "F6" || other.tag == "F7" || other.tag == "F8")
    299.             {
    300.                 GameObject AAAA2 = Instantiate(SB, other.transform.position, Quaternion.identity) as GameObject;
    301.                 AAAA2.GetComponent<Structurebreak_sound_controller>().debounce = Random.Range(0, 10);
    302.                 other.gameObject.GetComponent<Rigidbody>().isKinematic = false;
    303.                 SC_Caught caught = other.GetComponent<SC_Caught>();
    304.                 if (!caught)
    305.                 {
    306.                     caught = other.gameObject.AddComponent<SC_Caught>();
    307.                 }
    308.  
    309.                 caught.Init(this, r, tornadoStrength);
    310.  
    311.                 if (!caughtObject.Contains(caught))
    312.                 {
    313.                     caughtObject.Add(caught);
    314.                 }
    315.             }
    316.  
    317.             if (other.tag == "Glass")
    318.             {
    319.                 Destroy(other.gameObject);
    320.                 GameObject AAAA = Instantiate(GB, other.transform.position, Quaternion.identity) as GameObject;
    321.             }
    322.         }
    323.     }
    324.  
    325.     void OnTriggerExit(Collider other)
    326.     {
    327.         //Release caught object
    328.         SC_Caught caught = other.GetComponent<SC_Caught>();
    329.         if (caught)
    330.         {
    331.             caught.Release();
    332.  
    333.             if (caughtObject.Contains(caught))
    334.             {
    335.                 caughtObject.Remove(caught);
    336.             }
    337.         }
    338.     }
    339.  
    340.     public float GetStrength()
    341.     {
    342.         return rotationStrength;
    343.     }
    344.  
    345.     //The axis the caught objects rotate around
    346.     public Vector3 GetRotationAxis()
    347.     {
    348.         return rotationAxis;
    349.     }
    350.  
    351.     //Draw tornado radius circle in Editor
    352.     void OnDrawGizmosSelected()
    353.     {
    354.         Vector3[] positions = new Vector3[30];
    355.         Vector3 centrePos = transform.position;
    356.         for (int pointNum = 0; pointNum < positions.Length; pointNum++)
    357.         {
    358.             // "i" now represents the progress around the circle from 0-1
    359.             // we multiply by 1.0 to ensure we get a fraction as a result.
    360.             float i = (float)(pointNum * 2) / positions.Length;
    361.  
    362.             // get the angle for this step (in radians, not degrees)
    363.             float angle = i * Mathf.PI * 2;
    364.  
    365.             // the X & Y position for this angle are calculated using Sin & Cos
    366.             float x = Mathf.Sin(angle) * maxDistance;
    367.             float z = Mathf.Cos(angle) * maxDistance;
    368.  
    369.             Vector3 pos = new Vector3(x, 0, z) + centrePos;
    370.             positions[pointNum] = pos;
    371.         }
    372.  
    373.         Gizmos.color = Color.cyan;
    374.         for (int i = 0; i < positions.Length; i++)
    375.         {
    376.             if (i == positions.Length - 1)
    377.             {
    378.                 Gizmos.DrawLine(positions[0], positions[positions.Length - 1]);
    379.             }
    380.             else
    381.             {
    382.                 Gizmos.DrawLine(positions[i], positions[i + 1]);
    383.             }
    384.         }
    385.     }
    386.  
    387. }
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,546
    Because this function isn't what is passed, it's just something you've made up. Have you looked at the docs? As you can see it doesn't pass the two colliders but only the one.