Search Unity

disapering script

Discussion in 'Getting Started' started by vindawg2009, Jun 30, 2018.

  1. vindawg2009

    vindawg2009

    Joined:
    Jun 30, 2018
    Posts:
    1
    how do you make a script that when an object touches another object it dissapears? thanks in advace
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    "Disappears" as in the object gets destroyed, disabled, or turns invisible?
     
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Take a look at the physics system and specifically OnCollisionEnter and OnTriggerEnter methods. One of those will be what you'd normally use to detect when an object "touches" another object.

    After that, as Cucci_A asked, you need to decide what you mean by "disappears". You can destroy the object with a Destroy call, you can disable the object, you could disable its mesh renderer, you could swap or modify its material so it becomes transparent, and I'm sure there are more options. How you choose to make it transparent would depend on what you want to do with the object in the future, or if you want to have this be part of some disappearing effect (like having it fade out instead of instantly vanish).