- Home /
Question by
Bokaii · Jan 16, 2016 at 07:53 PM ·
listaccessing from any script
Acces list from another script
How do you access a list from another script? I can't seem to get it to work.
My code looks something like:
//Script
public listScript script;
void Update()
{
print(script.list[0]);
}
Comment
Best Answer
Answer by ShadyProductions · Jan 16, 2016 at 08:43 PM
public List<int> iList = new List<int>();
then from another script, you find your script using
GetComponent<SCRIPTNAME>().iList[0]
That is what I was doing, but this does not work. I keep getting an error.
did you assign public listScript script;
in your Start method otherwise its just empty. Share your error maybe I can see what you're doing wrong.
Answer by JollyBro · Jan 18, 2016 at 05:43 PM
Did you set the list as a static variable?
In the other script (the class you want to get the script from) the script variable has to be public static listScript script