Pro_Unit

PrefabPlanePlacer

Oct 28th, 2020
866
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2.  
  3. public class PrefabPlanePlacer : MonoBehaviour
  4. {
  5.     [SerializeField] private GameObject _prefab;
  6.     [SerializeField] Vector2Int _rowsColums = Vector2Int.one;
  7.     [SerializeField] Vector2 _offset = Vector2.one;
  8.  
  9.     [ContextMenu("InstatiateAsPrefab")]
  10.     void InstatiateAsPrefab()
  11.     {
  12.  
  13. #if UNITY_EDITOR
  14.         for (int x = 0; x < _rowsColums.x; x++)
  15.         {
  16.             for (int y = 0; y < _rowsColums.y; y++)
  17.             {
  18.                 var instance = (UnityEditor.PrefabUtility.InstantiatePrefab(_prefab) as GameObject).transform;
  19.  
  20.                 instance.SetParent(transform);
  21.  
  22.                 Vector3 offset = new Vector3(_offset.x, 0, _offset.y);
  23.  
  24.                 instance.localPosition = Vector3.Scale(new Vector3(x, 0, y), offset);
  25.             }
  26.         }
  27. #endif
  28.     }
  29. }
  30.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×