Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by BDX777 · Nov 30, 2015 at 08:38 PM · materialcharactercontrolleruvgameplay

Footsteps and Bulletholes based on Material UVs?

Hello, I'm stumped with this one. I'm trying to figure out how to access the Unity PBR material of a surface based on a raycast, and check whether or not it's shared material is in one of multiple lists that determine what footstep sound effect to play, what bullet hole texture to use, whether one surface makes more sound when you walk across it (thief: dark project stealth mechanic) and so many other interesting things.

I've been looking around Unity Answers, and I believe this can also be done with a CharacterController collision check? Could someone give me an example? It sounds familiar.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tanoshimi · Nov 30, 2015 at 09:06 PM 0
Share

You don't need a CharacterController - in fact, you've pretty much listed the correct approach already: perform a raycast downwards from the player, using the appropriate layermask to deter$$anonymous$$e the object on which they are standing. Then retrieve the sharedmaterial of the renderer component of that object, and compare it to your list. What part are you stuck on?

avatar image Fattie · Dec 01, 2015 at 04:44 AM 0
Share

"that deter$$anonymous$$e what footstep sound effect to play" wouldn't you just use a tag or layer - or nothing more than the name of the game object - for that? it seems really weird to go to the material.

As others have mentioned if (for some reason) you want the material just type .shared$$anonymous$$aterial. (Do NOT type ".material". If you don't know why, you don't want to know why :) )

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by rageingnonsense · Nov 30, 2015 at 09:13 PM

If I understand correctly, you are trying to find the physics material of a gameobject; correct? Have you tried:

 GetComponent<Collider>().sharedMaterial;

?

If you meant the shader material, try this:

 Material[] mats = GetComponent<MeshRenderer>().sharedMaterials;
 // now you have all materials assigned to this object; do what you want with them

or this if you only have one for each object:

 Material mat = GetComponent<MeshRenderer>().sharedMaterial;



Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by JonathanCzeck · Dec 01, 2015 at 02:36 PM

When you Raycast you can get a RaycastHit structure back on a hit. (Let's call that variable raycastHit) In that will be a variable called "collider". Now, either you have your meshes on this object or they are on some other object because you have a simplified collider.

If the collider is the same as the rendered mesh, then you can simply do: raycastHit.collider.GetComponent<Renderer>().sharedMaterial. If not, you will need to have a script that links the collider to the rendered mesh. (Call that ColliderToRendererLinker) You then would raycastHit.collider.GetComponent<ColliderToRendererLinker>().linkedRenderer.sharedMaterial.

Is that enough to guide you?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

40 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Importing Blender FBX into Unity (pictures) 1 Answer

Texture repeat (tiling) UV settings don't import in .fbx from 3ds Max 1 Answer

Keeping rigidbody upright in relation to slope 2 Answers

My Skybox Stopped Working... 3 Answers

Material doesn't have a color property '_Color' 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges