Search Unity

Way to Check off OnTrigger box on contact?

Discussion in 'Scripting' started by artistshc, Nov 26, 2017.

  1. artistshc

    artistshc

    Joined:
    Mar 7, 2015
    Posts:
    70
    Is there a way to check off the OnTrigger box when your object comes in contact with another object?

    Thanks.
     
  2. QuinnWinters

    QuinnWinters

    Joined:
    Dec 31, 2013
    Posts:
    308
    This will do it if you're trying to do it to the trigger collider the script is on. Just consider that if the object it's colliding with is not also a trigger that your object could travel partway into the other object before you turn off its trigger and that could potentially cause weird behavior.
    Code (CSharp):
    1. void OnTriggerEnter (Collider collider) {
    2.     if (collider.tag == "MyTag") {
    3.         transform.GetComponent <Collider> ().isTrigger = false;
    4.     }
    5. }
     
    artistshc likes this.
  3. artistshc

    artistshc

    Joined:
    Mar 7, 2015
    Posts:
    70
    Worked like a charm! Thank you so much!
     
unityunity