Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

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:
    545
    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:
    545
    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:
    545
    Looks like I thought correctly. It works.