I have created array of gameobjects and i want to know the index number of that object everytime it spawns. Here is the code. cars are prefabs, i want to know the index of car everytime it spawns.
using UnityEngine;
using System.Collections;
public class carspawner : MonoBehaviour {
public GameObject cars;
int carNo;
public float maxPos = 2.2f;
public float delayTimer = 0.5f;
float timer;
// Use this for initialization
void Start () {
timer = delayTimer;
}
// Update is called once per frame
void Update () {
//Debug.Log(timer);
timer -= Time.deltaTime;
if (timer <= 0)
{
Vector3 CarPos = new Vector3(Random.Range(-2.2f, 2.2f), transform.position.y, transform.position.z);
carNo = Random.Range(0,4);
Instantiate(cars[carNo], CarPos, transform.rotation);
Debug.Log(System.Array.IndexOf(cars, ""));
timer = delayTimer;
}
}
}