using System.Collections; using System.Collections.Generic; using UnityEngine; public class Button : MonoBehaviour { public Transform[] wall; public GameObject[] insideWallColliders; public bool pressed = false; public Sprite off; public bool bulletProof, changeSprite; public Sprite ChangedSprite; [Space(10)] public GameObject[] fallingPlatforms; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } private void OnCollisionEnter2D(Collision2D collision) { if ((collision.transform.tag == "Player") && !pressed) { Press(); } } public void Press() { if(fallingPlatforms != null){ foreach(GameObject platform in fallingPlatforms){ platform.GetComponent().ButtonFall(); } } if(insideWallColliders != null){ foreach(GameObject o in insideWallColliders){ o.SetActive(true); } } for (int i = 0; i < wall.Length; i++) { wall[i].GetComponent().enabled = !wall[i].GetComponent().enabled; if (wall[i].GetComponent()) { if (!changeSprite) { Color col = wall[i].GetComponent().color; if (wall[i].GetComponent().enabled) col.a = 1; else col.a = 0.25f; wall[i].GetComponent().color = col; }else { wall[i].GetComponent().sprite = ChangedSprite; } } for (int f = 0; f < wall[i].childCount; f++) { if (wall[i].GetChild(f).GetComponent()) { if (!changeSprite) { Color col = wall[i].GetChild(f).GetComponent().color; if (wall[i].GetComponent().enabled) col.a = 1; else col.a = 0.25f; wall[i].GetChild(f).GetComponent().color = col; }else { wall[i].GetChild(f).GetComponent().sprite = ChangedSprite; } } } } pressed = true; GetComponent().enabled = false; GetComponent().sprite = off; } }