Guest User

Untitled

a guest
Dec 9th, 2015
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3.  
  4. //[ExecuteInEditMode]
  5. public class ArrayModifier : MonoBehaviour {
  6.  
  7. public int repeat = 1;
  8. public float offset = 1;
  9.  
  10. public void Refresh() {
  11. Debug.Log("REFRESHHH3323");
  12.  
  13. DestroyAllChildren();
  14.  
  15. for (int i = 1; i < repeat; i++) {
  16. GameObject clone = GameObject.Instantiate(gameObject) as GameObject;
  17. clone.transform.parent = transform;
  18. clone.transform.position = transform.position;
  19. Vector3 pos = clone.transform.position;
  20. pos.x += offset * i;
  21. clone.transform.position = pos;
  22. clone.name = name + "_" + i;
  23. DestroyImmediate(clone.GetComponent<ArrayModifier>());
  24. }
  25. }
  26.  
  27. void DestroyAllChildren() {
  28. var children = new List<GameObject>();
  29. foreach (Transform child in transform) children.Add(child.gameObject);
  30. children.ForEach(child => DestroyImmediate(child));
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment