62 lines
2.1 KiB
C#
62 lines
2.1 KiB
C#
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<FallingPlatformButton>().ButtonFall();
|
|
}
|
|
}
|
|
|
|
if (wall != null){
|
|
for (int i = 0; i < wall.Length; i++){
|
|
wall[i].GetComponent<Collider2D>().enabled = !wall[i].GetComponent<Collider2D>().enabled;
|
|
if (wall[i].GetComponent<SpriteRenderer>()){
|
|
Color col = wall[i].GetComponent<SpriteRenderer>().color;
|
|
if (wall[i].GetComponent<Collider2D>().enabled)
|
|
col.a = 1;
|
|
else col.a = 0.25f;
|
|
wall[i].GetComponent<SpriteRenderer>().color = col;
|
|
}
|
|
for (int f = 0; f < wall[i].childCount; f++){
|
|
if (wall[i].GetChild(f).GetComponent<SpriteRenderer>()){
|
|
Color col = wall[i].GetChild(f).GetComponent<SpriteRenderer>().color;
|
|
if (wall[i].GetComponent<Collider2D>().enabled)
|
|
col.a = 1;
|
|
else col.a = 0.25f;
|
|
wall[i].GetChild(f).GetComponent<SpriteRenderer>().color = col;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
pressed = true;
|
|
GetComponent<Collider2D>().enabled = false;
|
|
GetComponent<SpriteRenderer>().sprite = off;
|
|
}
|
|
}
|