Can I check the name of an element?

Can I check the name of each element with other script?

For exampel check the element 6 from “Activator Script” with “Death Script”

Something like:

If element 6 name = “Death”
Do something;
If element 5 name = “Score”
Do something;

You can acess one scripts variables with another script by using

gameObject.GetComponent("Activator").Gamearray[ ]

What you can do is have a static class or a Singleton that will handle your “Level”. So he will store the number of death and score in the level (you can also have a DeathMax and ScoreMax values so you can adjust your design). Each time an element need to become : Null, Death or Score, it will ask the static class that will return what the element can be.

Here is the code of the manager. It replace both your Activator and your Checker scripts

using System.Collections.Generic;
using UnityEngine;

public class ActivatorManager : MonoBehaviour
{
    private ActivatorManager _instance = null;
    public ActivatorManager Instance
    {
        get { return _instance; }
    }

    public int NbScoreMax = 1;
    public int NbDeathMax = 1;

    public List<GameObject> Elements = null;

    private int _nbScore = 0;
    private int _nbDeath = 0;

    private void Awake()
    {
        _instance = GetComponent<ActivatorManager>();
    }

    private void Start()
    {
        List<int> availableElements = new List<int>();
        for (int i = 0; i < Elements.Count; i++)
        {
            availableElements.Add(i);
        }

        int index = Random.Range(0, availableElements.Count);
        int elementIndex = availableElements[index];
        availableElements.Remove(elementIndex);
        ActivateDeath(Elements[elementIndex]);

        index = Random.Range(0, availableElements.Count);
        elementIndex = availableElements[index];
        availableElements.Remove(elementIndex);
        ActivateScore(Elements[elementIndex]);

        for (int i = 0; i < Elements.Count; i++)
        {
            ActivateNull(Elements[availableElements*]);*

}
}

public void ActivateDeath(GameObject pGameObject)
{
if (_nbDeath < NbDeathMax)
{
_nbDeath++;
DesactivateNull(pGameObject);
pGameObject.GetComponent().enabled = true;
}
else
{
ActivateNull(pGameObject);
}
}

public void ActivateScore(GameObject pGameObject)
{
if (_nbScore < NbScoreMax)
{
_nbScore++;
DesactivateNull(pGameObject);
pGameObject.GetComponent().enabled = true;
}
else
{
ActivateNull(pGameObject);
}
}

public void ActivateNull(GameObject pGameObject)
{
pGameObject.GetComponent().enabled = true;
}

public void DesactivateDeath(GameObject pGameObject)
{
pGameObject.GetComponent().enabled = false;
_nbDeath–;
ActivateNull(pGameObject);
}

public void DesactivateScore(GameObject pGameObject)
{
pGameObject.GetComponent().enabled = false;
_nbScore–;
ActivateNull(pGameObject);
}
public void DesactivateNull(GameObject pGameObject)
{
pGameObject.GetComponent().enabled = false;
}
}