/*All this ox-specific logic needs to be moved to another script*/ private void SpawnOx(Collider other) { var OxenCountText = GameObject.Find("OxenCount").GetComponent <TextMeshPro>(); int OxenCount = 0; var quantity = other.GetComponent <Item>().Quantity; OxenCount += quantity; OxenCountText.text = OxenCount.ToString(); var yokeSpawnPoint = GameObject.Find("YokeSpawnPoint"); var yokePositions = GameObject.FindGameObjectsWithTag("YokePosition").Select(go => go.GetComponent <ItemStoragePosition>()); foreach (ItemStoragePosition yokePosition in yokePositions) { if (yokePosition.Occupied == false) { yokePosition.Occupied = true; NavMeshAgent yokeAgent = Instantiate(yokePrefab, yokeSpawnPoint.transform.position, Quaternion.identity).GetComponent <NavMeshAgent>(); AudioSource[] sounds = yokeAgent.GetComponentsInChildren <AudioSource>(); foreach (AudioSource sound in sounds) { if (sound.name == "Moo01") { sound.Play(); } if (sound.name == "Bell01") { sound.Play(); } } yokeAgent.destination = yokePosition.transform.position; break; } } }