using UnityEngine; using System.Collections; using System.Collections.Generic; public class openStructure : MonoBehaviour { public List objectsToFade = new List (); public Shader transparent; public Shader normalShader; public bool activate; public bool changed; public int option = 1; int i; //just a simple script to disable and enable part of the structure, using a transparent shader, so the player can go outside void Update () { if (activate) { if (!changed) { changeShader (); } for (i = 0; i < objectsToFade.Count; i++) { Color alpha = objectsToFade [i].GetComponent ().material.color; alpha.a += (Time.deltaTime / 2) * option; objectsToFade [i].GetComponent ().material.color = alpha; if (alpha.a <= 0 || alpha.a >= 1) { activate = false; disableObjects (); } } } } public void changeStructureState () { option *= (-1); activate = true; } void disableObjects () { for (int i = 0; i < objectsToFade.Count; i++) { if (option == -1) { objectsToFade [i].GetComponent ().enabled = false; } else { objectsToFade [i].GetComponent ().enabled = true; objectsToFade [i].GetComponent ().material.shader = normalShader; objectsToFade [i].GetComponent ().material.color = Color.white; } } if (option == 1) { changed = false; } } void changeShader () { for (int i = 0; i < objectsToFade.Count; i++) { if (option == -1) { objectsToFade [i].GetComponent ().material.shader = transparent; } } changed = true; } }