Unityでヘックス(六角形)をスクリプトで生成したのですが、playモードからSceneに戻ると全て消えてしまいます。
生成したオブジェクトをシーン上に残す方法はないのでしょうか?
検索して調べたのですが、解決方法が分かりませんでした。
回答お願いします。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class Map : MonoBehaviour { 6 7 public GameObject hexPrefab; 8 public GameObject Hex; 9 10 int width = 20; 11 int height = 20; 12 13 float xOffset = 0.882f; 14 float zOffset = 0.764f; 15 16 // Use this for initialization 17 void Start () { 18 for (int x = 0; x < width; x++) { 19 for (int y = 0; y < height; y++) { 20 21 float xPos = x * xOffset; 22 23 if (y % 2 == 1) { 24 xPos += xOffset / 2f; 25 } 26 27 GameObject hex_go = (GameObject)Instantiate(hexPrefab, new Vector3(xPos,0,y * zOffset), Quaternion.identity); 28 29 hex_go.name = "Hex_" + x + "_" + y; 30 31 hex_go.transform.SetParent (this.transform); 32 } 33 } 34 } 35 36 // Update is called once per frame 37 void Awake () { 38 39 } 40}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/11/17 13:19