I have this ingredients array which contains multiple variables (like name, icon, value etc.). When the player has surpassed certain points a new ingredient has to be added to that ingredients array. So I have an other array which contains icons and names for the new ingredients (values are to be added separately at runtime).
But the thing is you just can't use Add to add new elements to the ingredients array (also tried to give both arrays the same variables), or just add an new element at the end and fill the elements separately.
Script for unlocking ingredients:
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;
}
}
And part of the script for the players ingredients:
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;
}
Is there any way to add a new name and icon from the unlocking array, to the players ingredient array?
ingUnlock.Add(new ingUnlocks());does not work