Unity communicate between scripts
Notes of this tutorial
- not suggest use GameObject.Find(“obj”) : Walk through everything, not efficient.
you can use if you cannot avoid it.1
2GameObject.FindWithTag()
GameObject.FIndObjectsOfType<Unit>(); - Read only variable
1
2
3
4
5
6private List<Unit> _units = new List<Unit>();
public List<Unit> Unit => _units;
#or
public List<Unit> Units {get; private set;} = new List<Unit>();