Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. Material SphereMaterial;
  2.  
  3. // Use this for initialization
  4. void Start()
  5. {
  6. SphereMaterial = Resources.Load<Material>("Materials/man");
  7. if (SphereMaterial == null) Debug.Log("mat null");
  8. else Debug.Log("mat not null");
  9. Debug.Log("new Material: " + SphereMaterial.name);
  10. MeshRenderer meshRenderer = GetComponent<MeshRenderer>();
  11.  
  12. // Get the current material applied on the GameObject
  13. Material oldMaterial = meshRenderer.material;
  14. Debug.Log("Applied Material: " + oldMaterial.name);
  15. // Set the new material on the GameObject
  16. meshRenderer.material = SphereMaterial;
  17. }
  18.  
  19. public class ButtonHandler : MonoBehaviour {
  20.  
  21. public void ButtonInteract()
  22. {
  23. Debug.Log("changing matriel ");
  24. // Change the material of the game object here
  25.  
  26. }
  27. }
  28.  
  29. public class MaterialChangeButtonHandler : MonoBehaviour {
  30.  
  31. public MeshRenderer rendererToChange;
  32. public Material materialToChangeItTo;
  33.  
  34. public void ButtonInteract()
  35. {
  36. rendererToChange.sharedMaterial = materialToChangeItTo;
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement