Mouse button up and down to set true or false

Hello group, newbie here.

I’m trying to make an object disappear with the mouse button down and reappear when the mouse button is up to make it reappear

using UnityEngine;

public class TestKD : MonoBehaviour
{
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        
        {
            this.gameObject.active = false;
        }

        if (Input.GetMouseButtonUp(0))

        {
            this.gameObject.active = true;
        }
    }
}

It’s only working for the first part. The second part “true” is not reappearing. It also says the code is obsolete, but it puts me errors when it try GameObject.SetActive().

Any help would be very welcome.

thanks

Seb

Once the GameObject is disabled the scripts Update does not run anymore so it can’t re-enable itself. You will need another object that handles enabling and disabling of your desired object. Just create a gameobject reference and drag it into it in the inspector.

Why so unspecific? The more detailed you give us the error messages the more likely someone can help you with it.

You could shorten your code to:

referencedgameObject.active = Input.GetMouseButtonDown(0));