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; public GameObject _LevelManager1; private keyWhenPressed script1; bool isActivated; private AudioSource audioSource; // Reference to the AudioSource component public AudioClip pressedSound; // The sound clip to be played // Start is called before the first frame update void Start() { originalPointPosition = movingPoint.transform.position; audioSource = GetComponent(); } // Update is called once per frame void Update() { script1 = _LevelManager1.GetComponent(); isActivated = script1.isActivated; if (isActivated){ spriteRenderer.sprite = activatedSprite; } } void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("PressurePlatable") || other.CompareTag("PlayerIsOnIt")){ spriteRenderer.sprite = activatedSprite; movingPoint.transform.position = activatedPointPosition; audioSource.PlayOneShot(pressedSound); einsAn = true; } } void OnTriggerExit2D(Collider2D other) { if (other.CompareTag("PressurePlatable")|| other.CompareTag("PlayerIsOnIt")) { spriteRenderer.sprite = originalSprite; movingPoint.transform.position = originalPointPosition; einsAn = false; } } }