Ошибка CS0029 в коде для UNITY
Этот код был взят из книги по C# и Unity, но только вот что-то он не компилируется в юнити. Но я понять не могу это в книге код неправильный, или это я. Ошибка на линии 24,28
Полный текст ошибки:
Assets\Scripts\ApplePicker.cs(24,28): error CS0029: Cannot implicitly convert type 'UnityEngine.GameObject' to 'UnityEngine.GameObject[]'
РАБОЧИЙ КОД:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Apple : MonoBehaviour {
[Header("Set in Inspector")]
public static float bottomY = -20f;
void Update() {
if (transform.position.y < bottomY) {
Destroy (this.gameObject);
ApplePicker apScript = Camera.main.GetComponent<ApplePicker>();
apScript.AppleDestroyed();
}
}
}
НЕ РАБОЧИЙ КОД
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ApplePicker : MonoBehaviour
{
[Header("Set in Inspector")]
public GameObject basketPrefab;
public int numBaskets = 3;
public float basketBottomY = -14f;
public float basketSpacingY = 2f;
void Start()
{
for (int i = 0; i<numBaskets; i++) {
GameObject tBasketGO = Instantiate<GameObject>(basketPrefab);
Vector3 pos = Vector3.zero;
pos.y = basketBottomY + (basketSpacingY * i);
tBasketGO.transform.position = pos;
}
}
public void AppleDestroyed() {
GameObject[] tAppleArray=GameObject.FindGameObjectWithTag("Apple");
foreach (GameObject tGO in tAppleArray) {
Destroy(tGO);
}
}
}
Ответы (1 шт):
Автор решения: SoulOFTrue
→ Ссылка
Скорее всего в учебнике написано не так:
GameObject[] tAppleArray=GameObject.FindGameObjectWithTag("Apple");
А так:
GameObject[] tAppleArray=GameObject.FindGameObjectsWithTag("Apple");