| 1 | using System.Collections; |
| 2 | using System.Collections.Generic; |
| 3 | using UnityEngine; |
| 4 | |
| 5 | public class Pushbutton : Connectable |
| 6 | { |
| 7 | public PushButtonOnClick OnClick; |
| 8 | [SerializeField] private float buttonRestPosition, buttonClickedPosition; |
| 9 | [SerializeField] private Transform buttonTransform; |
| 10 | private Tween pushTween = new Tween(Easing.Linear); |
| 11 | |
| 12 | void Start() |
| 13 | { |
| 14 | pushTween.onChange = t => |
| 15 | { |
| 16 | buttonTransform.localPosition = Curving.Lerp(new Vector3[] |
| 17 | { |
| 18 | new Vector3(0, buttonRestPosition, 0), |
| 19 | new Vector3(0, buttonClickedPosition, 0), |
| 20 | new Vector3(0, buttonRestPosition, 0) |
| 21 | }, t); |
| 22 | }; |
| 23 | } |
| 24 | |
| 25 | public override void Activate() |
| 26 | { |
| 27 | base.Activate(); |
| 28 | |
| 29 | SFXSpawner.StartSFX(SFXSpawner.Sounds.Click, transform.position); |
| 30 | |
| 31 | pushTween.Start(0, 1, 0.6f); |
| 32 | |
| 33 | OnClick?.Invoke(); |
| 34 | } |
| 35 | |
| 36 | public delegate void PushButtonOnClick(); |
| 37 | } |