using System.Collections; using System.Collections.Generic; using UnityEngine; public class ButtonFalling : MonoBehaviour{ public Transform[] wall; public bool pressed = false; public Sprite off; [Space(10)] public GameObject[] fallingPlatforms; private void OnCollisionEnter2D(Collision2D collision){ if ((collision.transform.tag == "Player") && !pressed || collision.gameObject.tag == "Bullet" && !pressed){ Press(); } } private void OnTriggerEnter2D(Collider2D collision) { if ((collision.transform.tag == "Player")) { Press(); } } public void Press(){ if (fallingPlatforms != null){ foreach (GameObject platform in fallingPlatforms){ platform.GetComponent().ButtonFall(); } } if (wall != null){ for (int i = 0; i < wall.Length; i++){ wall[i].GetComponent().enabled = !wall[i].GetComponent().enabled; if (wall[i].GetComponent()){ Color col = wall[i].GetComponent().color; if (wall[i].GetComponent().enabled) col.a = 1; else col.a = 0.25f; wall[i].GetComponent().color = col; } for (int f = 0; f < wall[i].childCount; f++){ if (wall[i].GetChild(f).GetComponent()){ 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; } } } } pressed = true; GetComponent().enabled = false; GetComponent().sprite = off; } }