我有這個成分數組,它包含多個變量(如名稱,圖標,值等)。當玩家超過某些點時,必須將新配料添加到配料陣列中。所以我有一個其他數組,其中包含新成分的圖標和名稱(值將在運行時分別添加)。將新變量添加到變量數組
但是,你只是不能使用添加添加新元素到配料數組(也試圖給兩個數組相同的變量),或者只是在最後添加一個新的元素,並單獨填充元素。
腳本解鎖成分:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class progressManager : MonoBehaviour {
private int ingUnlockLevel;
private int lockLevel = 0;
private int newIngScore = 500;
public List<ingUnlocks> ingUnlock = new List<ingUnlocks>();
public List<GameObject> lockedCraft = new List<GameObject>();
public Texture locks;
public Texture normal;
private bool upGrade;
public TextMesh nextIngredient;
// Update is called once per frame
void Update() {
nextIngredient.text = ingUnlock[lockLevel].name;
ingUnlockLevel = GetComponent<gameMechanics>().headScore;
if(ingUnlockLevel >= newIngScore){upGrade = true;}
if(upGrade == true){
GetComponent<productManager>().ingredient.;
newIngScore = newIngScore *2;
lockLevel+=1;
upGrade = false;
}
}
[System.Serializable]
public class ingUnlocks{
public string name;
public Texture icon;
}
}
和腳本的一部分,爲玩家配料:
using UnityEngine;
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class productManager : MonoBehaviour {
private class ingredientComparer : IComparer<ingredients>{
public int Compare(ingredients a, ingredients b)
{
return ((int) a.c2cPerc) - ((int) b.c2cPerc);
}
}
public List<ingredients> ingredient = new List<ingredients>();
}
[System.Serializable]
public class ingredients{
public string name;
public Texture icon;
public int score;
public int quantity;
public float c2cPerc;
public bool usable;
}
有沒有辦法從解鎖陣列添加一個新的名稱和圖標,以玩家配料陣列?
在此先感謝!
「但是,你只是不能使用添加添加新的元素到配料數組(也試圖給兩個數組相同的變量),或者只是在最後添加一個新的元素,並分別填充元素。 「爲什麼不? – Polyfun 2012-03-28 13:51:40
數組是不可變的,如果你想要一個增長的數據結構,可以使用List。 – MrFox 2012-03-28 13:52:26
所以,你說'ingUnlock.Add(new ingUnlocks());'不起作用 – 2012-03-28 13:53:56