Выдаёт ошибку IndexOutOfRangeException: Array index is out of range.
Вот первый скрипт
using UnityEngine;
using System.Collections;
public class SpawnMarker : MonoBehaviour {
GameObject[] enemy;
public int length = 0;
public int spawnLength = 0;
public GameObject marker;
public float[] posX;
public float[] posY;
void Update()
{
enemy = GameObject.FindGameObjectsWithTag("Enemy");
length = enemy.Length;
if (spawnLength < length)
{
Instantiate(marker, transform.position, transform.rotation);
PlayerPrefs.SetInt("Markers", spawnLength + 1);
spawnLength++;
}
for (int i = 1; i == length; i++)
{
posX[i] = enemy[i].transform.position.x;
posY[i] = enemy[i].transform.position.y;
}
}
}
ошибка в
posX[i] = enemy[i].transform.position.x;
Вот второй скрипт
using UnityEngine;
using System.Collections;
public class Marker : MonoBehaviour {
GameObject player;
GameObject enemy;
float PlayerX;
float PlayerY;
float MarkerRotate;
public GameObject ParentMarker;
public int numverEnemy;
int i = 0;
SpawnMarker SM;
public float EnemyPosX;
public float EnemyPosY;
void Awake()
{
player = GameObject.FindGameObjectWithTag("Character");
SM = player.GetComponent<SpawnMarker>();
}
void Start()
{
EN();
}
void Update()
{
PlayerX = player.transform.position.x;
PlayerY = player.transform.position.y;
MarkerRotate = ParentMarker.transform.rotation.z;
if (i == 0)
{
ParentMarker.transform.rotation = Quaternion.Euler(0, 0, MarkerRotate * -1);
i++;
}
ParentMarker.transform.position = new Vector2(PlayerX, PlayerY);
EnemyPosX = SM.posX[numverEnemy];
EnemyPosY = SM.posY[numverEnemy];
}
void EN()
{
numverEnemy = PlayerPrefs.GetInt("Markers");
}
}
Помогите, в чем ошибка?