BlueGit

blue-star ggj-2020

Files

ggj-2020 / Assets / GAME / Scripts / Components / Pushbutton.cs

Pushbutton.cs

Jam end
timfa Tim Falken · pushed by timfa · 6 years ago
f9387e84 History
Pushbutton.cs 980 B Download Raw
1using System.Collections;
2using System.Collections.Generic;
3using UnityEngine;
4
5public 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}