This commit is contained in:
Gerard Gascón 2025-04-24 14:15:32 +02:00
commit 8103d0d89d
514 changed files with 211049 additions and 0 deletions

View file

@ -0,0 +1,65 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ButtonEnableDisable : MonoBehaviour{
public bool pressed;
bool alreadyPressed;
[Space]
public Transform pressPos;
public float pressRadius;
public LayerMask whatIsPlayer;
bool press;
[Space]
public GameObject[] enable;
public GameObject[] disable;
public BoxCollider2D[] colliders;
[Space]
public Sprite enabledState;
public Sprite disabledState;
SpriteRenderer sprite;
// Start is called before the first frame update
void Start(){
sprite = GetComponent<SpriteRenderer>();
}
// Update is called once per frame
void Update(){
if (pressed && !alreadyPressed){
if(enable != null){
foreach(GameObject o in enable){
o.SetActive(true);
}
}
if (disable != null){
foreach (GameObject o in disable){
o.SetActive(false);
}
}
foreach(BoxCollider2D col in colliders){
col.enabled = false;
}
sprite.sprite = disabledState;
alreadyPressed = true;
}else if(!alreadyPressed){
press = Physics2D.OverlapCircle(pressPos.position, pressRadius, whatIsPlayer);
if (press){
pressed = true;
}
sprite.sprite = enabledState;
}
}
void OnDrawGizmos(){
Gizmos.DrawWireSphere(pressPos.position, pressRadius);
}
}