There is a code:
private GameObject PastObj; private GameObject[] AllUsing; public int Offset; private void Awake() { if (name != "1") { AllUsing = GameObject.FindGameObjectsWithTag("CatUpgradesParent"); foreach (GameObject Obj in AllUsing) if (Obj.name == (Int32.Parse(name) - 1).ToString()) PastObj = Obj; Debug.Log(name + " | " + GetComponent<RectTransform>().anchoredPosition.y + " - " + PastObj.GetComponent<RectTransform>().anchoredPosition.y + " obj " + PastObj.name + " " + PastObj.transform.root.GetComponent<CatUpgrade>().islight); } } private void Update() { if (PastObj.transform.root.GetComponent<CatUpgrade>().islight) Offset = -50; else Offset = -150; if (name != "1" && GetComponent<RectTransform>().anchoredPosition.y - PastObj.GetComponent<RectTransform>().anchoredPosition.y != Offset) transform.Translate(new Vector2(0, 1) * Time.deltaTime); } In the array AllUsing elements named:
- one
- 2
- 3
- four
In the Awake() method, foreach should from all elements of the AllUsing array find the one whose name corresponds to the name of the element on which the script is 1. But PastObj is always empty. Why?
UPD: This script hangs on all objects of the AllUsing array and all of them are tagged with CatUpgradesParent