2023-06-24 14:57:13 +02:00

44 lines
1.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class keyWhenPressed : MonoBehaviour
{
public GameObject objectToActivate;
public GameObject _LevelManager1;
private ButtonDOne script1;
public GameObject _LevelManager2;
private ButtonDTwo script2;
public GameObject _LevelManager3;
private ButtonDThree script3;
private AudioSource audioSource; // Reference to the AudioSource component
public AudioClip keyAppearSound; // The sound clip to be played
public bool isActivated;
private void Awake()
{
// Disable the object by default
objectToActivate.SetActive(false);
audioSource = GetComponent<AudioSource>();
}
private void Update()
{
script1 = _LevelManager1.GetComponent<ButtonDOne>();
script2= _LevelManager2.GetComponent<ButtonDTwo>();
script3 = _LevelManager3.GetComponent<ButtonDThree>();
bool eins = script1.einsAn;
bool zwei = script2.zweiAn;
bool drei = script3.dreiAn;
// Check if all three conditions are true and the object is not yet activated
if (eins && zwei && drei && !isActivated)
{
// Activate the object
audioSource.PlayOneShot(keyAppearSound);
objectToActivate.SetActive(true);
isActivated = true;
}
}
}