ChangeMaterial.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. // Use Script in parent Folder of all humans
  5. public class ChangeMaterial : MonoBehaviour
  6. {
  7. public Material highlightRed;
  8. public Material highlightGreen;
  9. private Vector3 center;
  10. // Needed size divided with 2, bc all humans have the same radius (would be twice as big)
  11. private float radius = 0.5f;
  12. // Start is called before the first frame update
  13. void Start()
  14. {
  15. // Gets all Transform components to get the position of them
  16. Component[] allTransformComponent = GetComponentsInChildren<Transform>();
  17. //this.GetComponent<MeshRenderer>().material = highlightRed;
  18. foreach(Transform transform in allTransformComponent)
  19. {
  20. center = transform.position;
  21. createCollisionSpheres(center, radius);
  22. }
  23. //center = this.GetComponent<Transform>().position;
  24. }
  25. private void createCollisionSpheres(Vector3 center, float radius)
  26. {
  27. // !!!!!!!!! use OverlapSphereNonAlloc instead
  28. Collider[] objectsColliding = Physics.OverlapSphere(center, radius);
  29. foreach(var coll in objectsColliding)
  30. {
  31. coll.SendMessage("Collision");
  32. }
  33. }
  34. private void Update()
  35. {
  36. }
  37. }