hey guys i'm trying to switch materials back while in arrays (multiple objects/multiple materials)

this is my first question so if I’m not in the correct format or rules please let me know and I’ll change it :slight_smile: okay I’m making an invisibility script which changes multiple objects and after i change them i want them to revert back after the invisibility runs out.

changing the materials works perfect but in Update()

they are not changing back there are 8 objects the first with 8 materials and the rest around 3 materials and most are different so i was hoping there is code to make it reset like when you exit the game play and go back to editor mode

this is main line i want to change

InvisablityGameObjects*.GetComponent<Renderer>().materials = Materials;*

below this is all the code i think you would need and thank for anyone helping :slight_smile:
public class TriggerPickUp : MonoBehaviour {

public GameObject GunSwaper = null;
public Text Display = null;
public int Weapon;
public int Picking;
public Health healthbar;
public AudioSource OverShield = null;
public GameObject UIMaster = null;
public GameObject[] InvisablityGameObjects;
public bool Invisible;
public Material[] Materials;
public int Counter = 0;
public Material[] mat_MainInvisible;
public float visabilityTimer = 5;

private void Update()
{
if(Invisible)
{
if (visabilityTimer < 5)
{
visabilityTimer += Time.deltaTime;
}
else
{
for (int i = 0; i < InvisablityGameObjects.Length; i++)
{
for (int j = 0, n = InvisablityGameObjects*.GetComponent().materials.Length; j < n; j++)*
{
InvisablityGameObjects*.GetComponent().materials = Materials;*
}
}
Invisible = false;
}
}
}

private void OnTriggerEnter(Collider other)
{
if (other.GetComponent())
{
for (int i = 0; i < InvisablityGameObjects.Length; i++)
{
for (int j = 0, n = InvisablityGameObjects*.GetComponent().materials.Length; j < n; j++)*
{
Materials = InvisablityGameObjects*.GetComponent().materials;*
InvisablityGameObjects*.GetComponent().materials = mat_MainInvisible;
_}
}
Invisible = true;
visabilityTimer = 0;
}*_

i figured it out at the end i used a dictionary instead

this is the new code if it helps anyone else you can remove this or tell me too if need be

in short it used the key of the dictionary (int) as the id of the GameObject it is on and then applies it to all materials to each GameObject

public class TriggerPickUp : MonoBehaviour {

    public GameObject GunSwaper = null;
    public Text Display = null;
    public int Weapon;
    public int Picking;
    public Health healthbar;
    public AudioSource OverShield = null;
    public GameObject UIMaster = null;
    public GameObject[] InvisablityGameObjects;
    public bool Invisible;
    public Dictionary<int, Material[]> Materials = new Dictionary<int, Material[]> { };
    public int Counter = 0;
    public Material[] mat_MainInvisible;
    public float visabilityTimer = 5;
    public int k = 5;

    private void Update()
    {
        if(Invisible)
        {
            if (visabilityTimer < 5)
            {
                visabilityTimer += Time.deltaTime;
            }
            else
            {
                for (int i = 0; i < InvisablityGameObjects.Length; i++)
                {
                    for (int j = 0, n = InvisablityGameObjects*.GetComponent<Renderer>().materials.Length; j < n; j++)*

{
InvisablityGameObjects_.GetComponent().materials = Materials*;
}
}
Invisible = false;
}
}
}*_

private void OnTriggerEnter(Collider other)
{
if (other.GetComponent())
{
for (int i = 0; i < InvisablityGameObjects.Length; i++)
{
for (int j = 0, n = InvisablityGameObjects*.GetComponent().materials.Length; j < n; j++)*
{
if(k != i)
{
Materials.Add(i, InvisablityGameObjects*.GetComponent().materials);*
k = i;
}
InvisablityGameObjects*.GetComponent().materials = mat_MainInvisible;
_}
}
Invisible = true;
visabilityTimer = 0;
}*_