Spirinaut/Assets/Scripts/ButtonEnableDisable.cs
Gerard Gascón 8103d0d89d init
2025-04-24 14:15:32 +02:00

65 lines
1.6 KiB
C#

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);
}
}