Unity预制问题

时间:2015-03-21 16:50:07

标签: unity3d instantiation terrain

我创建了一个地形预制件。 我把它传递给脚本,它被实例化(数百次)。 问题是预制件本身随着每个实例化而改变。 (它的名字和翻译)。 我该如何防止这种情况?

示例代码:

using UnityEngine;

using System.Collections;
using System.Collections.Generic;

public class LandCrafter : MonoBehaviour {

	public Terrain parentPiece;
	public Terrain randomPiece;
	

	void Start () {

		for (int i = 0; i<=maxLandBlocks; i++) {
			if (currentPlacedBlocks.Count <= maxLandBlocks) {
				pieceList = GameObject.FindGameObjectsWithTag ("randomTerrainPiece");
				LandCraft ();
			} else {
				randomPiece.name = "randomPieceOfLand";
				charCraft ();
			}
		}
	}
	

	void LandCraft(){

		someExistingLandPiece = (GameObject)pieceList [(int)Random.Range(0.0f,pieceList.Length)];
		test = someExistingLandPiece.transform.position;
	
			if (!currentPlacedBlocks.Contains (someExistingLandPiece.transform.position + Vector3.forward)) {
			Instantiate (randomPiece);
			randomPiece.name = "The" + i++;
			randomPiece.transform.position = someExistingLandPiece.transform.position + Vector3.forward;
			currentPlacedBlocks.Add (randomPiece.transform.position);
		}
}

1 个答案:

答案 0 :(得分:0)

事实证明,您实际上必须实例化预制件并将该实例“提供”给脚本。如果您直接喂预制件,您所做的一切都会自动应用..