ChangeModelTransMaterialTime.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using UnityEngine;
  2. // Use this Script in parent folder of all Humans
  3. public class ChangeModelTransMaterialTime: MonoBehaviour
  4. {
  5. [Header("Model Materials:")]
  6. public Material default_mat;
  7. public int groups;
  8. // Start is called before the first frame update
  9. private void Start()
  10. {
  11. Component[] allTransform = GetComponentsInChildren<Transform>(); // all possible children of parent object
  12. foreach (Transform child in allTransform)
  13. {
  14. if (child.parent == allTransform[0])
  15. {
  16. child.Find("BasicMotionsDummyModel").Find("DummyMesh").GetComponent<SkinnedMeshRenderer>().material = default_mat;
  17. Color instance_col = child.Find("BasicMotionsDummyModel").Find("DummyMesh").GetComponent<SkinnedMeshRenderer>().material.color;
  18. if(child.CompareTag("2021"))
  19. {
  20. instance_col.a = (float) 3 / groups;
  21. }
  22. else if (child.CompareTag("2020"))
  23. {
  24. instance_col.a = (float) 2 / groups;
  25. }
  26. else if (child.CompareTag("2019"))
  27. {
  28. instance_col.a = (float) 1 / groups;
  29. }
  30. else
  31. {
  32. instance_col.a = 0F;
  33. }
  34. child.Find("BasicMotionsDummyModel").Find("DummyMesh").GetComponent<SkinnedMeshRenderer>().material.color = instance_col;
  35. }
  36. }
  37. }
  38. }