public class HitBox : MonoBehaviour
{
private List<GameObject> Boxlist;
private Stack<GameObject> FreeGameobject;
private GameObject Box;
private GameObject Bullet;
private GameObject nowBox;
private float fireTime, nowTime;
// Use this for initialization
void Start()
{
//Boxlist = new List<GameObject>();
FreeGameobject = new Stack<GameObject>();
fireTime = 1f;
nowTime = 0f;
Box = Resources.Load("Wooden Box") as GameObject;
Bullet = Resources.Load("Bullet") as GameObject;
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 5; j++)
{
if(FreeGameobject.Count <= 0)
{
nowBox = Instantiate(Box);
}
else
{
nowBox = FreeGameobject.Pop();
}
nowBox.transform.position += new Vector3(-i, j, 0);
//Boxlist.Add(nowBox);
}
}
}
// Update is called once per frame
void Update()
{
}
}
如果不將nowBox加入list 是正常的,界面上顯示了50個箱子,但是如果將nowBox加入list就會不顯示了,但是list中是有這50個箱子的
uj5u.com熱心網友回復:
private GameObject nowBox 應放在 for(int i = 0; i < 10; i++) 回圈之內定義uj5u.com熱心網友回復:
我運行了你的代碼,沒出現你說的問題,問題可能出現在你其他的邏輯上面。uj5u.com熱心網友回復:
今天我也遇到同樣的問題了,查了一下資料,感覺應該處在private List<GameObject> Boxlist;這一句。因為UNITY會對public的物件做序列化,單不會對private的物件做序列化。
在這一句前面加上[HideInInspector][SerializedField]就行了。
uj5u.com熱心網友回復:
希望對你有幫助http://blog.csdn.net/wang371372/article/details/27209767
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/61395.html
標籤:Unity3D
上一篇:關于C#撰寫定時程式
