-
-
Save todorok1/452dc92acde611aa5628a03924afb69d to your computer and use it in GitHub Desktop.
SetParentのサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
/// <Summary> | |
/// 指定した数のゲームオブジェクトをインスタンス化するスクリプトです。 | |
/// </Summary> | |
public class ObjectMaker : MonoBehaviour | |
{ | |
// インスタンス化するPrefabオブジェクトをアサインします。 | |
public GameObject prefab; | |
// 親オブジェクトのトランスフォームをアサインします。 | |
public Transform parentTran; | |
// ゲームオブジェクトを生成する数を指定します。 | |
public int prefabNum; | |
void Start() | |
{ | |
InstantiatePrefab(); | |
} | |
/// <Summary> | |
/// ゲームオブジェクトをPrefabから作成する処理です。 | |
/// </Summary> | |
void InstantiatePrefab() | |
{ | |
for (int i = 0; i < prefabNum; i++) | |
{ | |
GameObject obj = Instantiate(prefab, Vector3.zero, Quaternion.identity); | |
obj.transform.SetParent(parentTran); | |
obj.transform.position = new Vector3(i, 0f, 0f); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment