2023-06-12 14:07:20 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class ButtonDTwo:MonoBehaviour
|
|
|
|
{
|
|
|
|
|
|
|
|
public SpriteRenderer spriteRenderer;
|
|
|
|
public Sprite originalSprite;
|
|
|
|
public Sprite activatedSprite;
|
|
|
|
public bool startActivated = false;
|
|
|
|
private Collider2D Stein = null;
|
|
|
|
public bool zweiAn = false;
|
2023-06-24 14:57:13 +02:00
|
|
|
private AudioSource audioSource; // Reference to the AudioSource component
|
|
|
|
public AudioClip pressedSound; // The sound clip to be played
|
2023-06-12 14:07:20 +02:00
|
|
|
// Start is called before the first frame update
|
|
|
|
void Start()
|
|
|
|
{
|
2023-06-24 14:57:13 +02:00
|
|
|
audioSource = GetComponent<AudioSource>();
|
2023-06-12 14:07:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
if (startActivated == true ) {
|
|
|
|
spriteRenderer.sprite = activatedSprite;
|
|
|
|
} else {
|
|
|
|
spriteRenderer.sprite = originalSprite;}
|
|
|
|
|
|
|
|
if(Stein!=null && Stein.CompareTag("PlayerIsOnIt")){
|
|
|
|
startActivated = true;
|
|
|
|
spriteRenderer.sprite = activatedSprite;
|
|
|
|
zweiAn = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnTriggerEnter2D(Collider2D other) {
|
|
|
|
Stein = other;
|
|
|
|
if (other.CompareTag("PressurePlatable")||other.CompareTag("Player")) {
|
|
|
|
startActivated = true;
|
|
|
|
spriteRenderer.sprite = activatedSprite;
|
2023-06-24 14:57:13 +02:00
|
|
|
if(!zweiAn){
|
|
|
|
audioSource.PlayOneShot(pressedSound);
|
|
|
|
}
|
2023-06-12 14:07:20 +02:00
|
|
|
zweiAn = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|