Не могу обратиться к объекту, как к элементу массива
Создал динамический массив и обычный. Суть в том, что в обычном лежат все варианты объектов(труб), а в динамическом все, заспавненные во время игры. Почему не получается обратиться к свойствам объекта, как к элементу массива?
public GameObject[] pipes = new GameObject[2];
public List<GameObject> allpipes;
allpipes.Add(pipes[0]);
Instantiate(pipes[0], Vector3.zero, Quaternion.identity);
Debug.Log(allpipes[lastpipe]);
allpipes[0].transform.Rotate(0, 0, speed * Time.deltaTime);
Полный код:
using System.Collections.Generic;
using UnityEngine;
public class control : MonoBehaviour
{
public GameObject[] pipes = new GameObject[2];
public List<GameObject> allpipes;
public Camera cam;
//public GameObject cpos;
public float offset = .6f;
private int lastpipe;
//private byte counter;
private bool win;
private float newpos = 0;
private byte nspd;
public byte speed = 55;
float ang;
void Awake()
{
nspd = speed;
//counter = 0;
win = false;
}
// Start is called before the first frame update
void Start()
{
//на старте создается труба 1
allpipes.Add(pipes[0]);
allpipes[0] = Instantiate(allpipes[0], Vector3.zero, Quaternion.identity);
}
// Update is called once per frame
void Update()
{
//вращение трубы
lastpipe = allpipes.Count - 1;
ang = allpipes[lastpipe].transform.rotation.eulerAngles.z;
Debug.Log(allpipes[lastpipe]);
allpipes[lastpipe].transform.Rotate(0, 0, speed * Time.deltaTime);
//Debug.Log(ang);
if (ang >= 173 && ang <= 182 | ang >= 353)
{
speed = 5;
}
else
{
speed = nspd;
}
if (Input.GetMouseButtonDown(1) && ang >= 173 && ang <= 181 | ang >= 353)
{
win = true;
//counter++;
newpos += 1.6f;
speed = 0;
cam.orthographicSize += 3f;
//cpos.transform.Translate(new Vector3(cpos.transform.position.x + offset, 0, 0));
}
if (win == true)
{
allpipes.Add(pipes[Random.Range(0, 2)]);
allpipes[lastpipe] = Instantiate(allpipes[lastpipe], Vector3.zero, Quaternion.identity);
//Instantiate(pipes[Random.Range(0,2)], new Vector3(newpos, 0, 0), Quaternion.identity);
win = false;
}
else if (win == true && allpipes[lastpipe] == pipes[1])
{
allpipes.Add(pipes[1]);
allpipes[lastpipe] = Instantiate(allpipes[0], Vector3.zero, Quaternion.identity);
win = false;
}