Cannot disable collider

I want to disable the collider of the object when I hide it. But now when it disappears, I go to the spot of the object and the event happens when I touches air! Should I just collider.enable = false or should I add more things?

Here’s my code just for reference:

public string type;
    public bool avail;
    public float time;
    public float appearTime;
    public float disappearTime;

    private Collider coll;

    // Use this for initialization
    void Start () {
        coll = this.GetComponent<Collider> ();
        time = Random.Range (1, 5);
        if (time < 2) {
            avail = false;
        } else {
            avail = true;
        }
    }
   
    // Update is called once per frame
    void Update () {
        time -= Time.deltaTime;
        if (time < 0f) {
            ShowAndHide ();
        }
    }
       
    void ShowAndHide(){
        if (avail) {
            time = disappearTime;
            avail = false;
            this.gameObject.GetComponent<Renderer> ().enabled = false;
            coll.enabled = false;
        }
        else {
            time = appearTime;
            avail = true;
            this.gameObject.GetComponent<Renderer> ().enabled = true;
            coll.enabled = true;
        }

Ok, I’m not going to answer your question but I will offer an alternative for you to try.

In stead of trying to disable the Renderer component and the collider, use this:

this.gameObject.setActive(true);

this.gameObject.setActive(false);

I think this will do what you’re trying to do.

I tried this. But this would stop the timer. What I want is to let the timer continue to run when the object disappears.

Try moving your timer to your game manage or other script so it’s not disabled with the game object.

Oh! Ok I get what you mean. Thank you!