This commit is contained in:
Gerard Gascón 2025-04-24 16:56:52 +02:00
commit 862afc9b7a
478 changed files with 197737 additions and 0 deletions

88
Assets/Scripts/Button.cs Normal file
View file

@ -0,0 +1,88 @@
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<PlataformaFalling>().ButtonFall();
}
}
if(insideWallColliders != null){
foreach(GameObject o in insideWallColliders){
o.SetActive(true);
}
}
for (int i = 0; i < wall.Length; i++)
{
wall[i].GetComponent<Collider2D>().enabled = !wall[i].GetComponent<Collider2D>().enabled;
if (wall[i].GetComponent<SpriteRenderer>())
{
if (!changeSprite)
{
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;
}else
{
wall[i].GetComponent<SpriteRenderer>().sprite = ChangedSprite;
}
}
for (int f = 0; f < wall[i].childCount; f++)
{
if (wall[i].GetChild(f).GetComponent<SpriteRenderer>())
{
if (!changeSprite)
{
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;
}else
{
wall[i].GetChild(f).GetComponent<SpriteRenderer>().sprite = ChangedSprite;
}
}
}
}
pressed = true;
GetComponent<Collider2D>().enabled = false;
GetComponent<SpriteRenderer>().sprite = off;
}
}