Prefabを増やした時に、Prefabが作られる位置を変えたい
前回、Prefab関連の事で質問をさせていただいた初心者です。
Prefabを増やした時に、増やしたPrefabの位置を変えたいのですが、どうにも思った通りの位置に変える事が出来ません。
GameObject prefab = Instantiate(obj,new Vector3(-0.3f, -3.0f * count, 0.0f), Quaternion.identity);
Vector3の()内を(-29, 312 *count, 0)にすると、作られたPrefabの座標がx=-3712、y=39936といったようにCanvasから遠く離れた位置になってしまいます。
解決方法や原因を教えていただけると大変助かります・・。
何卒よろしくお願いします。
該当のソースコード
using System; using System.Collections; using System.Collections.Generic; using UnityEditor; using UnityEngine; public class CreateManager : MonoBehaviour { //Canvasコンポーネントの付いたオブジェクトをアタッチしておく public Transform CanvasNyuryoku; int count = 1; // 初期化 void Start() { } // Update is called once per frame void Update() { } public void PushKari() { // ResourcesフォルダからButtonプレハブのオブジェクトを取得 GameObject obj = (GameObject)Resources.Load("Button01"); //ButtonのPrefabを+を押した分だけ増やす //Instantiate( 生成するオブジェクト, 場所, 回転); GameObject prefab = Instantiate(obj,new Vector3(-0.3f, -3.0f * count, 0.0f), Quaternion.identity); prefab.name = "Button" + count.ToString(); ButtonPrefab Button = prefab.GetComponent<ButtonPrefab>(); prefab.transform.SetParent(CanvasNyuryoku); prefab.transform.localScale = Vector3.one; count++; } }
コード内の「+」は、Game上においてPrefabが増えているか確認するため、OnClickとしてScriptを付けているButtonオブジェクトになります
補足情報(FW/ツールのバージョンなど)
・Unity 2018.2.16f1
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。