Don't work array error out of range

Hello guys, i don’t really know what’s wrong, when i start game i see over 999 errors where array index is out of range.

using UnityEngine;
using System.Collections;

public class AI : MonoBehaviour {
public Transform[ ] takas;
public float MoveSpeed = 4;
public float MaxDist = 10;
public float MinDist = 5;
public int i = 0;

// Use this for initialization
void Start () {
takas [0] = GameObject.Find (“1”).transform;
takas [1] = GameObject.Find (“2”).transform;
takas [2] = GameObject.Find (“3”).transform;
takas [3] = GameObject.Find (“4”).transform;
takas [4] = GameObject.Find (“5”).transform;
takas [5] = GameObject.Find (“6”).transform;
takas [6] = GameObject.Find (“7”).transform;
takas [7] = GameObject.Find (“8”).transform;
takas [8] = GameObject.Find (“9”).transform;
}

// Update is called once per frame
void Update () {
transform.LookAt(takas*);*
_ if(Vector3.Distance(transform.position, takas*.position) > 1)*_
_ transform.position += transform.forward * MoveSpeed * Time.deltaTime;_

_ if (Vector3.Distance (transform.position, takas*.position) <= 3) {
i++;
}
}
}*_

At the start of your “Start” function add this:

takas = new Transform[9];

Or better still use a List:

using UnityEngine;
using System.Collections.Generic;

public class AI : MonoBehaviour {
    public List<Transform> takas = new List<Transform>();
    public float MoveSpeed = 4;
    public float MaxDist = 10;
    public float MinDist = 5;
    public int i = 0;

    // Use this for initialization
    void Start () {
		// And you could use a loop instead for cleaner code :)
        for (int i = 1; i <= 9; ++i)
            takas.Add(GameObject.Find (i.ToString()).transform);
    }

    // ...

I hope that this helps!

You should add code tags to your post to make your source code more readable :slight_smile:
http://forum.unity3d.com/threads/143875-Using-code-tags-properly