Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections.Generic;
- //[ExecuteInEditMode]
- public class ArrayModifier : MonoBehaviour {
- public int repeat = 1;
- public float offset = 1;
- public void Refresh() {
- Debug.Log("REFRESHHH3323");
- DestroyAllChildren();
- for (int i = 1; i < repeat; i++) {
- GameObject clone = GameObject.Instantiate(gameObject) as GameObject;
- clone.transform.parent = transform;
- clone.transform.position = transform.position;
- Vector3 pos = clone.transform.position;
- pos.x += offset * i;
- clone.transform.position = pos;
- clone.name = name + "_" + i;
- DestroyImmediate(clone.GetComponent<ArrayModifier>());
- }
- }
- void DestroyAllChildren() {
- var children = new List<GameObject>();
- foreach (Transform child in transform) children.Add(child.gameObject);
- children.ForEach(child => DestroyImmediate(child));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment