Get pixel from Rotated Texture2D

I am firing a raycast beam downward and changing the pixel it hits to red, the code works perfectly when orientated as shown in the first image, but when i rotate it 90 degrees it doesnt work correctly. The five red cubes each fire a raycast beam down into the center of the circle and change the pixel hit to red. What do i need to change to get it to work in the second orientation ?

image 1 (works):
[49250-screenshot2.png*_|49250]

image 2 (does not work):
[49251-screenshot1.png*_|49251]

My Code:

for(int i=0; i<PunchPin.Count;i++){ //looping through cubes
			Debug.DrawRay(PunchPin*.transform.position,Vector3.down,Color.cyan);*
  •  	RaycastHit hit;*
    

_ Physics.Raycast(PunchPin*.transform.position,Vector3.down, out hit);_
_
if(hit.collider !=null){_
_
if(hit.collider.gameObject.name == PunchTape.gameObject.name){_
_
MeshRenderer rend = hit.collider.gameObject.GetComponent();_
_
Texture2D tex = (Texture2D)rend.material.mainTexture;_
_
Vector2 uv;_
_
uv.x = (hit.point.x - hit.collider.bounds.min.x) / hit.collider.bounds.size.x;_
_
uv.y = (hit.point.z - hit.collider.bounds.min.z) / hit.collider.bounds.size.z;_
_
Vector2 texCoord = hit.textureCoord2;_
_ tex.SetPixel((int)(uv.x * tex.width), (int)(uv.y * tex.height),Color.red);_
_
tex.Apply();_
_
}_
_
}_
_
}_
_

_*

You rotate the image in the scene using it’s transform (or RectTransform, doesn’t matter). But the source texture is always unrotated, so you need to rotate the hitpoint when calculating the pixel position.

Old question but…
You don’t need to use rotations, the raycast hit provides the UV coordinates in textureCoord. It will work properly for any rotation if you do:

Vector2 pixelUV = hit.textureCoord;
pixelUV.x *= tex.width;
pixelUV.y *= tex.height;

tex.SetPixel((int)pixelUV.x, (int)pixelUV.y, Color.red);
tex.Apply();