Search Unity

Question Getting to the material from a Raycast hit

Discussion in 'Getting Started' started by tleylan, Feb 9, 2023.

  1. tleylan

    tleylan

    Joined:
    Jun 17, 2020
    Posts:
    618
    I have a bullet and a collision is detected when it hits an object in the room. Using OnTriggerEnter I am passed a Collider "hit". I just want to affect the game object in some way so I'm exploring which components I can get to from there. These is a material on the hit object but it seems to be a physics material so for instance I don't see a color property (if I wanted to change the color).

    At the moment I printed hit.name and I'm about to test hit.gameObject.name

    Am I misunderstanding how this works?
     
  2. tleylan

    tleylan

    Joined:
    Jun 17, 2020
    Posts:
    618
    Ah, I think I seethe collider only has a physics material. I think I need to get the renderer and from there I can get the materials. I THINK :)
     
  3. tleylan

    tleylan

    Joined:
    Jun 17, 2020
    Posts:
    618
    Looks like I thought correctly. It works.