58 lines
1.6 KiB
C#
Raw Normal View History

2023-06-12 14:07:20 +02:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ButtonDOne: MonoBehaviour
{
public SpriteRenderer spriteRenderer;
public Sprite originalSprite;
public Sprite activatedSprite;
public GameObject movingPoint;
public Vector3 activatedPointPosition;
private Vector3 originalPointPosition;
public bool einsAn = false;
2023-06-18 13:37:19 +02:00
public GameObject _LevelManager1;
private keyWhenPressed script1;
bool isActivated;
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()
{
originalPointPosition = movingPoint.transform.position;
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()
{
2023-06-18 13:37:19 +02:00
script1 = _LevelManager1.GetComponent<keyWhenPressed>();
isActivated = script1.isActivated;
if (isActivated){
spriteRenderer.sprite = activatedSprite;
}
2023-06-12 14:07:20 +02:00
}
void OnTriggerEnter2D(Collider2D other) {
if (other.CompareTag("PressurePlatable") || other.CompareTag("PlayerIsOnIt")){
spriteRenderer.sprite = activatedSprite;
movingPoint.transform.position = activatedPointPosition;
2023-06-24 14:57:13 +02:00
audioSource.PlayOneShot(pressedSound);
2023-06-12 14:07:20 +02:00
einsAn = true;
}
}
void OnTriggerExit2D(Collider2D other) {
if (other.CompareTag("PressurePlatable")|| other.CompareTag("PlayerIsOnIt")) {
spriteRenderer.sprite = originalSprite;
movingPoint.transform.position = originalPointPosition;
2023-06-18 13:37:19 +02:00
einsAn = false;
2023-06-12 14:07:20 +02:00
}
}
}