12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- // Use Script in parent Folder of all humans
- public class ChangeMaterial : MonoBehaviour
- {
- public Material highlightRed;
- public Material highlightGreen;
- private Vector3 center;
- // Needed size divided with 2, bc all humans have the same radius (would be twice as big)
- private float radius = 0.5f;
- // Start is called before the first frame update
- void Start()
- {
- // Gets all Transform components to get the position of them
- Component[] allTransformComponent = GetComponentsInChildren<Transform>();
- //this.GetComponent<MeshRenderer>().material = highlightRed;
- foreach(Transform transform in allTransformComponent)
- {
- center = transform.position;
- createCollisionSpheres(center, radius);
- }
- //center = this.GetComponent<Transform>().position;
- }
- private void createCollisionSpheres(Vector3 center, float radius)
- {
- // !!!!!!!!! use OverlapSphereNonAlloc instead
- Collider[] objectsColliding = Physics.OverlapSphere(center, radius);
- foreach(var coll in objectsColliding)
- {
- coll.SendMessage("Collision");
- }
- }
- private void Update()
- {
- }
- }
|