BlueGit

blue-star ggj-2020

Files

ggj-2020 / Assets / GAME / Scripts / Modules / FCO_R1.cs

FCO_R1.cs

Jam end
timfa Tim Falken · pushed by timfa · 6 years ago
f9387e84 History
FCO_R1.cs 2.1 KiB Download Raw
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using UnityEngine;
5
6public class FCO_R1 : ModuleBase
7{
8 [SerializeField] private Connector light, flipswitch, goodBtn;
9
10 private bool goodBtnPressed;
11
12 protected override bool TestCorrectness()
13 {
14 return goodBtnPressed;
15 }
16
17 // Start is called before the first frame update
18 void Start()
19 {
20 goodBtn.OnConnect = c =>
21 {
22 if (c is Pushbutton)
23 {
24 Pushbutton btn = (Pushbutton)c;
25
26 btn.OnClick = () =>
27 {
28 bool ok = true;
29
30 if (light.Connected != null)
31 {
32 if (light.Connected is LightComponent)
33 {
34 //ok
35 }
36 else
37 {
38 ok = false;
39 }
40 }
41 else
42 {
43 ok = false;
44 }
45
46 if (flipswitch.Connected != null)
47 {
48 if (flipswitch.Connected is FlipSwitch)
49 {
50 if (!((FlipSwitch)flipswitch.Connected).IsFlipped)
51 {
52 ok = false;
53 }
54 }
55 else
56 {
57 ok = false;
58 }
59 }
60 else
61 {
62 ok = false;
63 }
64
65 goodBtnPressed = ok;
66
67 if (ok)
68 ((LightComponent)light.Connected).TurnOn(Color.blue);
69
70 if (!ok)
71 EjectComponents();
72 };
73 }
74 };
75
76 goodBtn.OnDisconnect = c =>
77 {
78 if (c is Pushbutton)
79 {
80 Pushbutton btn = (Pushbutton)c;
81
82 btn.OnClick = null;
83 }
84 };
85 }
86}