I currently have an array with two variables inside that I want to initialize in script instead of using it in unity editor. If it is possible I would greatly appreciate a solution!
Yes, it should look something like this (also works for List)
using System.Collections.Generic;
public class MyItem
{
public int id;
public string name;
}
public class MyScript
{
public MyItem[] myItemstems = new MyItem[]
{
new MyItem(){ id = 1 , name = "Item1"},
new MyItem(){ id = 2 , name = "Item2"},
};
}
Also viable for dictionaries
using System.Collections.Generic;
public class MyItem
{
public int id;
public string name;
}
public class MyScript
{
public Dictionary<int , MyItem> myItemDict= new Dictionary<int,MyItem>()
{
{ 1 , new MyItem(){ id = 1 , name = "Item1" }},
{ 2 , new MyItem(){ id = 1 , name = "Item2" }}
};
}