47 lines
1.1 KiB
C#
Raw Normal View History

2023-05-21 14:22:14 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjPressurePlateMod: MonoBehaviour
{
public GameObject door;
public SpriteRenderer spriteRenderer;
public Sprite originalSprite;
public Sprite activatedSprite;
2023-06-24 13:49:28 +02:00
public AudioSource audioSource; // Reference to the AudioSource component
public AudioClip buttonClickSound; // The sound clip to be played
private bool isActive = false;
2023-05-21 14:22:14 +02:00
// Start is called before the first frame update
void Start()
{
2023-06-24 13:49:28 +02:00
audioSource = GetComponent<AudioSource>();
2023-05-21 14:22:14 +02:00
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter2D(Collider2D other) {
if (other.CompareTag("PressurePlatable")){
door.SetActive(false);
spriteRenderer.sprite = activatedSprite;
2023-06-24 13:49:28 +02:00
if(!isActive){
audioSource.PlayOneShot(buttonClickSound);
isActive = true;
}
2023-05-21 14:22:14 +02:00
}
}
2023-05-21 14:50:43 +02:00
/*
2023-05-21 14:22:14 +02:00
void OnTriggerExit2D(Collider2D other) {
if (other.CompareTag("PressurePlatable")) {
door.SetActive(true);
spriteRenderer.sprite = originalSprite;
2023-05-21 14:22:14 +02:00
}
}
2023-05-21 14:50:43 +02:00
*/
2023-05-21 14:22:14 +02:00
}