How can i hide objects that they are in top of the object that i click?

Hallo, i have a scene with 5 cubes, one up to the other. When i click on one of them it must be hidded with all the other, that are on top of it. Can someone wright me a script for this scene, because i have not experiens on it.

First of all, “write me a script” is against the purpose of Unity Answers.

Here is how you can do it:

You need an array of GameObjects or Transforms that hold references to all the stacked cubes.
You use Physics.Raycast to cast a ray from the camera’s position towards where the mouse cursor is in screen space.
If it hits a cube, then you access it’s Renderer and set the Renderer’s componentm to enabled = false.
Then you iterate through the array of cubes and check each one’s transform.position.y. If it’s bigger than the transform.position.y of the cube you hit, then you also set thies cube’s Renderer component to enabled = false.