How to access and modify the "Read/Write Enabled" values of a Texture2D from code

I want to do this from code, because I’m making a Texture2D by reading the pixels from the screen, and then I want to access each pixel in order to make a heightmap out of it. I can’t access each pixel if I don’t set the Texture’s Read/Write Enabled value to true.

I also don’t know if it accessible without the texture type being set to “advanced”, so maybe this has to be changed as well.

A Texture2D is always readable and writable. For a Texture object, the read/write enabled option can only be set in the import options.