- Home /
Question by
Gabe-Tucker · Nov 30, 2019 at 06:50 AM ·
c#unity 5scripting beginner
How to update a value within a List in another script?
Hi there! I need to understand how, in Script 1, to find a public List created in Script 2, and create a local clone of it in Script 1 so that I can search through its values. I then, also through Script 1, would like to be able to edit Script 2's public List's values. How should I approach this? Thanks!
Comment
Best Answer
Answer by oTaijjo · Nov 30, 2019 at 11:29 AM
Don't know if I got you right:
public class Script1 : MonoBehaviour
{
// Inject script2 in the Inspector
public Script2 script2;
public void Foo()
{
// Access like this
List<int> theList = script2.list;
// Do whatever you want with theList here.
// Since it is passed by reference, you don't
// need to do anything else, after modification
}
}