Getting variables that from an array of scripts


My scene has aliens that each has a lifetimer, when an alien is killed a manager script should register the life time of that alien. Right now i cant figure out how to get the independant scripts from the aliens in the manager script. I thought of using an array of scripts but the array is empty everytime i run the scene …

This is the manager script:

using UnityEngine;
using System.Collections;

public class Manager : MonoBehaviour {

    public AlienScript[] alienScripts;
    public float[] lifeTimers;

	void Start () {
       alienScripts = GetComponents<AlienScript>();

Does anyone have tips on how to get the alien scripts and how to store their life timers in an array?

Thank you.

alienScripts = FindObjectsOfType();

but personally, i would make the manager a Singleton and let the alienscripts register themselves on creation and remove on Destroy.

Add this above your “public AlienScript alienScripts” declaration:

private static Manager instance = null;
public static Manager managerController
        if (instance == null)

            instance = GameObject.Find("NameOfManagerObjectHere").GetComponent<Manager>();
        return instance;

Then, create a new function:

public void SaveLifeTimers(float time)
    // add to your lifeTimers array here!

Inside your Alien script now, create a new function:

void SaveTime()
    float lifeTime; // Whatever your time is