Finding screen pixel coordinate using RGBA

hi everyone, i am rather new to unity here. I am not sure which sub forum of post my question in so I apologise in advance if my question if not related to this forum.

I would like to ask if there is a way to get the screen pixel location through the pixel colour (RGBA). I first used GetPixel(mouse location) to find the pixel colour of where my mouse clicked on (canvas image of my gameobject). Then, I would get an array of colour pixels of the screen from which i got the image from. Finally, using an if statement, if the element of the array pixel matches the colour pixel of the mouse location, a cube will be spawned at the pixel location. Are there any functions that would aid me ? Any advice or help is greatly appreciated. Thank you :).

What you’ve described rings some alarms.
If your objective is really as straightforward as placing a cube where you click, then why not cast a ray from camera to determine the position(Unity - Scripting API: Physics.Raycast)? Better yet, if you know the distance from camera where then cube needs to be spawned, it becomes a simple vector addition without rays.

If you have a reason for iterating an array of colours please explain further. Also what is your current algorithm going to do if you have multiple pixels of the same colour?

Hi BakeMyCake, I realised that I took my project in the wrong direction. I would not need to iterate the array of colours but I will on the other hand play around with raycasts. Thank you for your advice on raycasts :slight_smile: