A
A
alekseibulankin2021-02-03 14:07:24
Unity
alekseibulankin, 2021-02-03 14:07:24

Why in Unity3D does RaycastHit.textureCoord always return 0.0 after building the project?

I need to get the color of a pixel from a texture when a Raycast ray collides with an object. In the unity editor, everything works fine, the coordinates of the collision of the ray and the color of the pixel are determined. After building the application, RaycastHit.textureCoord always returns coordinates (0,0), so the color of the pixel is also incorrect. Has anyone encountered such a problem? And how can you solve it?

A fragment of the code for obtaining the texture of an object when a ray collides with a surface and determining the color of a pixel:
Texture2D tex = (Texture2D)Calc_Data.hit_center.collider.gameObject.GetComponent().material.mainTexture; // Get texture of object
color_pixcel = tex.GetPixelBilinear(Calc_Data.hit_center.textureCoord.x, Calc_Data.hit_center.textureCoord.y); // Get color from texture

The object itself:
601a80c8f370d076348824.png

Object material: Object
601a80e10573f391628110.png

texture:
601a80d7ed3bc844284090.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question