MegaRuntimeAttach.cs 863 B

12345678910111213141516171819202122232425262728293031
  1. 
  2. using UnityEngine;
  3. // Example script Attaches object at every vertex on the the deforming mesh
  4. public class MegaRuntimeAttach : MonoBehaviour
  5. {
  6. public GameObject ExternalRecprtor;
  7. void Start()
  8. {
  9. Vector3[] v = GetComponent<MegaModifyObject>().sverts;
  10. for ( int i = 0; i < v.Length; i++ )
  11. {
  12. GameObject mag = new GameObject();
  13. mag.name = "Attach" + i;
  14. mag.transform.parent = gameObject.transform;
  15. mag.transform.position = transform.localToWorldMatrix.MultiplyPoint3x4(v[i]);
  16. MegaAttach ma = mag.AddComponent<MegaAttach>();
  17. ma.target = gameObject.GetComponent<MegaModifyObject>();
  18. ma.radius = 0.1f;
  19. ma.AttachIt(transform.localToWorldMatrix.MultiplyPoint3x4(v[i]));
  20. GameObject rec = (GameObject)Instantiate(ExternalRecprtor);
  21. rec.transform.parent = mag.transform;
  22. rec.transform.localPosition = Vector3.zero;
  23. }
  24. }
  25. }