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

Enable/Disable GameObject with same TriggerBox

Discussion in 'Scripting' started by nincs, Jul 1, 2016.

  1. nincs

    nincs

    Joined:
    Mar 25, 2015
    Posts:
    65
    Hi!

    I have a box collider (tirgger box enabled) and I would like to activate and disactivate a GameObject with theat. Once, when I touch the collider get the Object active, and when I tuch again, get disactive.

    Can anybody help me?
     
  2. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Code (csharp):
    1.  
    2. [SerializeField]
    3. GameObject threat;
    4.  
    5. void OnTriggerEnter(Collider other)
    6. {
    7.     threat.SetActive(!threat.activeSelf);
    8. }
    9.  
     
    nincs likes this.
  3. nincs

    nincs

    Joined:
    Mar 25, 2015
    Posts:
    65
    Thank you very much! Unfoirtunatly it's not working for me, hoe can I use it?
     
  4. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    That's not an adequate description of the problem :)