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

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:
    79
    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:
    490
    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:
    79
    Worked like a charm! Thank you so much!