0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

unity > 粒子を倍々にしていく (失敗編)

Last updated at Posted at 2015-08-09
動作確認
Unity 5.1.1-f on MacOS X 10.8.5

倍々ゲームをしたい。
最初1つの粒子がある。そこに1つ足す。
次は2つ足す。
次は4つ足す。
。。。

PrefabUtilyを使えばよさそうだが、うまくいかなかった。
とりあえず動くコードは以下。Main Cameraに関連付ける。
prefabBaseにはSphere(Rigidbodyつき)を関連付けた。

ButtonPushed.cs
using UnityEngine;
using System.Collections;
//using UnityEditor; // for PrefabUtility

public class ButtonPushed : MonoBehaviour {

	public GameObject prefabBase;
	private GameObject GOmonomer;
	
	private GameObject sphGroup; // for grouping
	private const string kGroupName = "UnitedSphere";
	
	void Start () {
		GameObject sphGroup = new GameObject (kGroupName);
		Vector3 pos1 = new Vector3(0.0f, 0.0f, 0.0f);
		GOmonomer = Instantiate(prefabBase, pos1, Quaternion.identity) as GameObject;
		GOmonomer.name = "monomer";
		GOmonomer.transform.parent = sphGroup.transform;
	}

	void OnGUI() {
		if (GUI.Button (new Rect (10, 10, 100, 40), "Generate")) {
			Vector3 pos1 = new Vector3(0.0f, 2.0f, 0.0f);

			// replace of prfabBase
			prefabBase = GameObject.Find (kGroupName);		

			GOmonomer = Instantiate(prefabBase, pos1, Quaternion.identity) as GameObject;
			GOmonomer.name = "monomer1";

			GOmonomer.transform.parent = GameObject.Find(kGroupName).transform;
		}
	}

}

Untitled_-150809_unitePrefab-PC__Mac___Linux_Standalone__Personal.jpg

うまく行ってない点は左側の階層構造に重複ができている点。

parentを整理しなおしたらいいのだろうか?

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?