44 lines
1.3 KiB
C#
Raw Permalink Normal View History

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