forellenforderung3/Assets/AssetsFORELLE/Script/PlayerPressurePlateMod.cs

52 lines
1.2 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerPressurePlateMod: MonoBehaviour
{
2023-06-24 13:49:28 +02:00
public SpriteRenderer spriteRenderer;
public Sprite originalSprite;
public Sprite activatedSprite;
public GameObject door;
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
public AudioClip doorOpenSound;
private bool isActive = false;
// Start is called before the first frame update
void Start()
{
2023-06-24 13:49:28 +02:00
audioSource = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter2D(Collider2D other) {
//if (other.CompareTag("Player")) {
// spriteRenderer.sprite = activatedSprite;
//}
spriteRenderer.sprite = activatedSprite;
2023-06-24 13:49:28 +02:00
if(!isActive){
audioSource.PlayOneShot(buttonClickSound);
audioSource.PlayOneShot(doorOpenSound);
isActive = true;
}
door.SetActive(false);
}
/*
void OnTriggerExit2D(Collider2D other) {
if (other.CompareTag("Player")) {
spriteRenderer.sprite = originalSprite;
}
spriteRenderer.sprite = originalSprite;
}
*/
}