- Home /
Finding What Material Is On The Object Player Collided With.
So I have an array of textures that are randomly assigned to an array of game objects. When the player collides with the object I want the player to collide with a specific texture from the array and then do something.
This code is when the player collides with one of the objects in the array:
As for now it prints no. If you need more information please ask me and thank you.
Answer by twosuliman · May 26, 2020 at 07:44 PM
you can get the material by using other.material
.
and so you can compare it with a set of materials, like this:
foreach(Material material in myMaterials)
{
if(material == other.material)
{
//code
}
}
@twosuliman Thank you for replying, I was wondering shouldn't I be using texture ins$$anonymous$$d of material since the array of textures is what I use to set on the game objects? I know that unity then changes it to the material for example I had a folder of images but then It created a folder automatically of materials of these images. I also use the other to detect if the player collides with a game object so how would I make it so if the player collides with a game object check for if that game object has a specific material/texture?
@twosuliman Thank you I got it working so that when the player stands on the textures it always prints no but I want to tell it if it stands on a specific texture out of three let's say it will then print yes? It should not be printing no so I am assu$$anonymous$$g it is because other.material is looking for material but I am using textures or am I incorrect? If so Is there a way to test against the texture?
Edit I added this to the code although it always prints the last else statement.
Your answer
Follow this Question
Related Questions
Changing the material at runtime for multiple objects in a single call 0 Answers
Array for multiple cameras? 2 Answers
OnTriggerEnter/Exit firing unexpectedly 0 Answers
OnEnterTrigger wont work 2 Answers