using UnityEngine;
public class KostylScript : MonoBehaviour
{
public ButtonTrigger _button;
public bool _isPressed;
public void ButtonOff()
{
if (_isPressed)
{
_button.OnButtonExit();
Debug.Log("Jest");
}
}
}
using UnityEngine;
using UnityEngine.Events;
public class ButtonTrigger : MonoBehaviour
{
[SerializeField] private Animator _anim;
[SerializeField] private MeshRenderer _buttonbase;
[SerializeField] private Texture _materialOff;
[SerializeField] private Texture _materialOn;
[SerializeField] private ButtonTrigger _base;
[SerializeField] private AudioSource _onSound;
[SerializeField] private AudioSource _offSound;
public UnityEvent _onPressed;
public UnityEvent _onReleased;
private void OnTriggerStay(Collider other)
{
OnButtonStay();
if(other.tag == "Cube")
{
other.GetComponent<KostylScript>()._isPressed = true;
other.GetComponent<KostylScript>()._button = _base;
OnButtonStay();
}
}
private void OnTriggerExit(Collider other)
{
OnButtonExit();
}
private void OnButtonStay()
{
_anim.SetBool("isDown", false);
_onPressed.Invoke();
_buttonbase.material.mainTexture = _materialOn;
}
public void OnButtonExit()
{
_anim.SetBool("isDown", true);
_buttonbase.material.mainTexture = _materialOff;
_onReleased.Invoke();
Debug.Log("Exit");
}
hit.collider.transform.GetComponent<KostylScript>().OnButtonExit();
hit.collider.transform.GetComponent<KostylScript>()._isPressed = false;